home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / ncsat.cpt / Telnet2.5 final / main / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-16  |  85.2 KB  |  3,244 lines

  1. #pragma segment NewTel        /* NCSA 2.5 */
  2. /*#define NEW_STUFF 1        /* BYU - changed to "MacTCPdriver" for use in Make file. */
  3. #ifdef lint
  4. static char *SCCSid = "%W%    (NCSA)    %G%";
  5. #endif
  6. /*
  7. *    menu.c
  8. *     by Gaige B. Paulsen
  9. ****************************************************************************
  10. *    Part of NCSA Telnet for the Macintosh                                   *
  11. *                                                                          *
  12. *      Uses    :                                                               *
  13. *      TCP/IP kernel for NCSA Telnet                                       *
  14. *      by Tim Krauskopf                                                    *
  15. *       with Macintosh code by Gaige B. Paulsen                                 *
  16. *                                                                          *
  17. *      National Center for Supercomputing Applications                     *
  18. *      152 Computing Applications Building                                 *
  19. *      605 E. Springfield Ave.                                             *
  20. *      Champaign, IL  61820                                                *
  21. *                                                                          *
  22. *                                                                          *
  23. ****************************************************************************
  24. *
  25. *    Menu Handling and initialization code.
  26. *
  27. *    Called by:
  28. *        event.c
  29. *        maclook.c
  30. */
  31.  
  32. /*
  33.  *    Files to be included in the compile
  34.  *
  35.  */
  36.  
  37. #include    <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <ctype.h>
  41.  
  42. #include    <Desk.h>
  43. #include    <Dialogs.h>
  44. #include    <Events.h>
  45. #include    <Fonts.h>
  46. #include    <Lists.h>            /* NCSA */
  47. #include    <Memory.h>
  48. #include    <Menus.h>
  49. #include    <OsUtils.h>
  50. #include    <Packages.h>
  51. #include     <Printing.h>
  52. #include    <Quickdraw.h>
  53. #include    <Resources.h>        /* BYU 2.4.12 */
  54. #include    <Scrap.h>
  55. #include    <ToolUtils.h>
  56. #include <Strings.h>
  57.  
  58. #include "alias.h"                /* NCSA: alias definitions */
  59. #include "protocol.h"
  60. #include    "wind.h"
  61. #include     "configrec.h"
  62.  
  63. #include    "hostform.h"
  64. #include    "prefs.h"
  65. #include "netevent.h"
  66. #include "dlayer.h"
  67. #include "util.h"
  68. #include "rsmac.h"
  69. #include "user.h"
  70. #include "maclook.h"
  71. #include "macutil.h"
  72. #include "vrrgmac.h"
  73. #include "rgmp.h"
  74. #include "tekrgmac.h"
  75. #include "vgtek.h"
  76. #include "vsinterf.h"
  77. #include "event.h"
  78. #include "config.h"
  79. #include "mactools.h"
  80. #include "confile.h"
  81. #include <MacTCPCommonTypes.h>
  82. #include <AddressXlation.h>
  83. #include "ser.h"                /* BYU 2.4.15 */
  84. #include "slip.h"                /* BYU 2.4.15 */
  85. /*#include "dnr.c"                /* BYU 2.4.15 */
  86.  
  87. #ifdef MPW
  88. #include "mpw.h"
  89. #endif MPW
  90.  
  91. /*
  92.  *    Resource Defines
  93.  */
  94.  
  95. /*----------------------------------------------------------------*/
  96. /* NCSA: these are the new defines for the alias code */
  97.  
  98. #define kListMods 0
  99.  
  100. #define AliasDLOG    130
  101. #define kAliasOutline    12
  102. #define kAliasHostItem    9
  103. #define kAliasPortItem    10
  104. #define kAliasAliasItem    11
  105. #define kAliasRemove    4
  106. #define kAliasCancel    2
  107. #define kAliasOK        1
  108. #define kAliasAdd        3
  109. #define kAliasList        13
  110. /*-----------------------------------------------------------------*/
  111.  
  112. #define    DLOGOk        1
  113. #define DLOGCancel    2
  114.  
  115. #define MacroDLOG    500        /* The Macros dialog */
  116. #define QuitDLOG    2010    /* The Quit Confirmation Dialog */
  117. #define    CloseDLOG    2001    /* The Close Confirmation Dialog */
  118.  
  119. #define    SessionDLOG    257        /* The Session initialization dialog ----------- */
  120. #define    Shost        5        /* The Destination field in GetDest dialog */
  121. #define Sname        7        /* Session name in session dialog */
  122. #define Sftponly    9        /* BYU - Indicates an FTP only session */
  123. #define Sserialonly    10        /* BYU 2.4.15 - Indicates a serial port session */
  124.  
  125. #define SConfigDLOG    260        /* The Session configuration dialog ------------ */
  126. #define    SChost        4        /* Put the session name here [STATIC]  */
  127. #define SCname        6        /* Session name in session dialog */
  128. #define SCwidth132    8        /* Session width is 132 */
  129. #define SCwidth80    9        /* Session width is 80 */
  130. #define SCkbbs        11        /* Keyboard Backspace default */
  131. #define SCkbdel        12        /* Keyboard Delete default */
  132. #define    SCscrolon    13        /* Session scrollback toggle */
  133. #define SCscrolnum    14        /* Session scrollback number of lines */
  134. #define    SCtekclear    17        /* Session Tek <esc> ^L clears screen */
  135. #define    SCtekcreate    18        /* Session Tek <esc> ^L creates new window */
  136. #define SCcrLF        20        /* Session cr translates to <cr><lf> */
  137. #define SCcrNUL        21        /* Session cr translates to <cr><nul> */
  138. #define SCechoBuff    23        /* Session echo mode buffers (local edit ) */
  139. #define SCechoSend    24        /* Session echo mode sends (half duplex ) */
  140. #define SCtekold    27        /* TEK 4014 emulation */
  141. #define SCteknew    28        /* TEK 4105 emulation */
  142. #define SClineY        30        /* Line mode on */                        /* BYU 2.4.9 */
  143. #define SClineN        31        /* Line mode off */                        /* BYU 2.4.9 */
  144. #define SCeightY    33        /* Eight bits of font displayed */        /* BYU 2.4.9 */
  145. #define SCeightN    34        /* Seven bits of font displayed */        /* BYU 2.4.9 */
  146. #define SCtekdis    35        /* NCSA 2.5: disabe TEK entirely */
  147.  
  148. #define    LinesDLOG    272        /* The number of lines config dialog ----------- */
  149. #define    LinesNumber    5        /* User given # of lines */
  150.  
  151. #define SetupDLOG   273     /*  Setup keys interface */
  152.  
  153. #define StatusDLOG    270        /* Inactive connection status dialog */
  154. #define BadDynDLOG    280        /* Bad Dynamic IP Number search */
  155.  
  156. #define PGRECT    (*prRecHdl)->prInfo.rPage        /* Macro for making the pagerect more accessible */
  157.  
  158.  
  159. /*
  160.  *    Defines for the menu handling code.
  161.  */
  162.  
  163. #define    appleMenu    1        /*    Apple Menu ID */
  164. #define    NfileMenu    512        /*    File Menu Resource ID */
  165. #define    NeditMenu    513        /*    Edit Menu Resource ID */
  166. #define NtermMenu    514        /*    Emulation Menu Resource ID */
  167. #define    NconnMenu    515        /*    Connection Menu Resource ID */
  168. #define NnetMenu    516        /*    Network Menu Resource ID */
  169.  
  170. #define    fileMenu    256        /*    File Menu ID */
  171. #define    editMenu    257        /*    Edit Menu ID */
  172. #define termMenu    258        /*    Emulation Menu ID */
  173. #define    connMenu    259        /*    Connection Menu ID */
  174. #define netMenu        260        /*    Network Menu Resource ID */
  175. #define fontMenu    128        /*  Font Menu Resource ID */
  176. #define sizeMenu    129        /*    Size Menu Resource ID */
  177.  
  178. #define    Fil            1        /*    File Menu's Position */
  179. #define Edit        2        /*  Edit Menu's Position */
  180. #define    Emul        3        /*    Emulation Menu's position */
  181. #define Net            4        /*    Network Menu's position */
  182. #define Conn        5        /*    Connection Menu's position */
  183. #define Font        6        /*    Font Menu's position */
  184. #define Size        7        /*  Size Menu's position */
  185.  
  186. /* ----------------- The File Menu ---------------------- */
  187. #define FLopen        1        /* File Menu: Open Connection */
  188. #define    FLclose        2        /* File Menu: Close Connection */
  189. #define    FLload        4        /* File Menu: Load Set */
  190. #define    FLsave        5        /* File Menu: Save Set */
  191. #define FLftp        7        /* File Menu: ftp on */
  192. #define FLbin        8        /* File Menu: MacBinary on */
  193. #define FLlog        9        /* File Menu: ftp log on */
  194. #define FLdir         10        /* File Menu: Set Transfer Directory */
  195. #define FLprint        12        /* File Menu: Print Selection */
  196. #define FLpset        13        /* File Menu: Page Setup */
  197. #define FLquit        15        /* File Menu: Quit */
  198. #define FLsession    16        /* ftp session */
  199.  
  200. /* ----------------- The Edit Menu ---------------------- */
  201. #define    EDundo        1
  202. #define EDcut        3
  203. #define EDcopy        4        /* Edit Menu: Copy */
  204. #define EDpaste        5        /* Edit Menu: Paste */
  205. #define EDclear        6        /* Edit Menu: Clear */
  206. #define EDcopyt        7        /* Edit Menu: Copy Table */
  207. #define EDmacros    9        /* Edit Menu: Macros */
  208. #define EDprefs        10        /* Edit Menu: Preferences */
  209.  
  210. /* ----------------- The Session Menu ---------------------- */
  211. #define EMbs        1        /* Emulation Menu: backspace */
  212. #define EMdel        2        /* Emulation Menu: delete */
  213. #define EMecho        4        /* Emulation Menu: echo */
  214. #define EMwrap      5       /* Emulation Menu: Wrap mode on/off */
  215. #define EMscroll    6        /* Emulation Menu: Clear Screen Saves Lines */
  216. #define EMreset     7        /* Emulation Menu: Reset Terminal */
  217. #define EMjump        8        /* Emulation Menu: Jump Scroll */
  218. #define EMpage        9        /* Emulation Menu: TEK Page command */
  219. #define EMclear        10        /* BYU 2.4.8 - Emulation Menu: TEK Page clears screen */
  220. #define EMlines        12        /* Emulation Menu: Set Usable Lines */
  221. #define EMsetup     13      /* Emulation Menu: Setup keys */
  222. #define EMfont        14        /* Emulation Menu: Font */
  223. #define EMsize        15        /* Emulation Menu: Size */
  224. #define EMcolor        16        /* Emulation Menu: Color */
  225. #define EMslip        18        /* BYU 2.4.15 - Emulation Menu: Switch to SLIP */
  226. #define EMserial    19        /* BYU 2.4.15 - Emulation Menu: Switch to Serial */
  227. #define EMcapture    21        /* BYU 2.4.18 - Emulation Menu: Capture to file */
  228.  
  229. /* ----------------- The Network Menu ---------------------- */
  230. /* #define NEcommand    19    Emulation Menu: Command Keys */
  231. #define    NEftp        1        /* Emulation Menu: Send ftp command */
  232. #define    NEip        2        /* Emulation Menu: Send IP # */
  233. #define NEayt        4        /* Emulation Menu: Send "Are You There" */
  234. #define NEao        5        /* Emulation Menu: Send "Abort Output" */
  235. #define NEinter        6        /* Emulation Menu: Send "Interrupt Process" */
  236. #define NEec        7        /* Emulation Menu: Send "Erase Character" */
  237. #define NEel        8        /* Emulation Menu: Send "Erase Line" */
  238. #define NEscroll    10        /* Network Menu: Scroll Lock */
  239. #define NEnet        12        /* Network Menu: Show Net #'s */
  240. #define NEconfig    13        /* Network Menu: Configure Network */
  241. #define NEserial    14        /* Network Menu: Serial Port Settings */    /* BYU serial */
  242. #define NEalias        15        /* NCSA: alias menu item    */
  243.  
  244.  
  245. #define YESFTP 1
  246. #define NOFTP 0
  247.  
  248. #define    NMENUS    8            /*    We have NMENUS menus right now */
  249.  
  250. #define COnext        1        /* Connection Menu: Next Session... */
  251. #define CR            0x0d    /* the carriage return character */
  252. #define    BS            0x08    /* the backspace character */
  253. #define TAB            9
  254.  
  255. /*
  256.  *    Internal Variable declarations 
  257.  */
  258.  
  259. short 
  260.     modalItems,                /* BYU 2.4.15 */
  261.     modalItem[3] = {0,0},    /* BYU 2.4.15 - Item no. for modal cmd key feature */
  262.     modalKey[3],            /* BYU 2.4.15 - Key code for modal cmd key feature */
  263.     *FontNumber = 0L;        /* Array of Font Numbers */
  264. int
  265.     *FontSize = 0L;            /* Array of Font Sizes */
  266. int
  267.     nFontNumber=0,            /* # of font Numbers */
  268.     nFontSize = 0,            /* # of font sizes */
  269.     ScrlLock=0,                /* Are we in network suspend mode */
  270.     ftpavail=0,                /* Is ftp available (default yes ) */    /* BYU 2.4.12 */
  271.     ftplogon=0,                /* Is ftp log visible (default no) */
  272.     whichMenus=0;            /* 0 is old 1 is new */
  273.  
  274. extern SysEnvRec theWorld;    /* BYU 2.4.18 - System Environment record */
  275.  
  276. extern short 
  277.     serial_scrn,        /* BYU 2.4.15 */
  278.     slip_connection;    /* BYU 2.4.15 */
  279.  
  280. extern Cursor
  281.     *graphcurs,        /* Cursor when in graphic window */
  282.     *normcurs;        /* Cursor for non-transfer normal mode */
  283.  
  284. extern Handle hKCHR;        /* BYU 2.4.12 - Handle for keyboard mapping stuff (event.c) */
  285.  
  286. THPrint
  287.     prRecHdl=0L;            /* our print record handle */
  288.  
  289. MenuHandle
  290.     myMenus[NMENUS];        /* Menu Handles .... */
  291.  
  292. char
  293.     stupidarray[150];        /* A stupid array for finding the stringwidth */
  294.  
  295. short setdir;
  296.  
  297. #define VMARGINS 4
  298.  
  299. /*
  300.  * External variable declarations (those which we borrow )
  301.  *
  302.  */
  303. extern WindRec
  304.     *screens,            /* The screen array from Maclook */
  305.     ftplog,                    /* The FTP log screen from Maclook */
  306.     console;
  307.  
  308. extern short cmask;
  309.  
  310. extern int
  311.     done,                /* BYU */
  312.     KIP,
  313.     MacBinary,
  314.     EtherNet,
  315.     dynamic,
  316.     userlevel,
  317.     ctrl,                    /* Control key ... */
  318.     scrn,                    /* The current screen from Maclook */
  319.     numwindows;                /* The number of windows now from Maclook */
  320. extern int
  321.     HasColor;
  322.  
  323. long
  324.     defmask,        /* The network mask as per defaults contingent on the IP */
  325.     mynetmask;        /* The network mask as per user config */
  326.  
  327. unsigned char
  328.     KIPserver[4],            /* BYU 2.4.15 - KIP gateway address */
  329.     SLIP_ip_number[];        /* BYU 2.4.15 */
  330.  
  331. DialogPeek    myDPeek;
  332.  
  333. char tempspot[256];                /* temporary storage */
  334.  
  335.  
  336. extern unsigned char
  337.     myipnum[4],                /* My current IP Number from Maclook */
  338.     nnmyaddr[4];            /* My cuurent hardware address  from Maclook */
  339.  
  340. extern Str255
  341.     *defaultd,        /* Default host name */
  342.     *dvs;            /* Default Volume/directory specification */
  343. /*
  344.  * Internal predeclared functions
  345.  */
  346. pascal void
  347.     VersionNumber(),
  348.     OutlineItem();
  349. pascal short
  350.     modalProc();
  351. void
  352.     printsleep();            /* The netsleep/ print cancel procedure */
  353.  
  354. PicHandle
  355.     RGtoPICT();                /* Convert Drawings to pictures */
  356. int
  357.     portsOpen();            /* 0 if none, 1 if active, -1 if not active */
  358.  
  359.  
  360. /*
  361.  * External predeclared functions
  362.  */
  363. extern char
  364.     **RSGetTextSel();        /* Convert text to char handle  from RSmac */
  365.  
  366. char *strncpy();
  367.  
  368. extern void close_mb_files();    /* BYU */
  369.  
  370. #ifndef MPW
  371. Str255 *ptoc(),*ctop();
  372. #endif MPW
  373.  
  374.  
  375. CloseCaptureFile(int w) {
  376.     VSclosecapture(w);                                /* BYU 2.4.18 */
  377.     CheckItem(myMenus[Emul], EMcapture,FALSE);        /* BYU 2.4.18 */
  378. }
  379.  
  380.  
  381. /* Allow the operator to "Switch to Serial" only when         /* BYU 2.4.15 */
  382. /* all of the SLIP connections have been closed.            /* BYU 2.4.15 */
  383.                                                             /* BYU 2.4.15 */
  384. /* Allow the operator to "Switch to SLIP" only when         /* BYU 2.4.15 */
  385. /* the front most session is a serial session.                /* BYU 2.4.15 */
  386.                                                             /* BYU 2.4.15 */
  387. SLIP_menus() {                                                /* BYU 2.4.15 */
  388.     short i;                                                /* BYU 2.4.15 */
  389.                                                             /* BYU 2.4.15 */
  390.     if (serial_scrn>=0) {                                    /* BYU 2.4.15 */
  391.                                                             /* BYU 2.4.15 */
  392.         if (!slip_connection) {                                /* BYU 2.4.15 */
  393.                                                             /* BYU 2.4.15 */
  394.             if (screens[scrn].connectionType == 0)            /* BYU 2.4.15 */
  395.                 DisableItem (myMenus[Emul], EMslip);        /* BYU 2.4.15 */
  396.             else                                            /* BYU 2.4.15 */
  397.                 EnableItem (myMenus[Emul], EMslip);            /* BYU 2.4.15 */
  398.                                                             /* BYU 2.4.15 */
  399.             DisableItem (myMenus[Emul], EMserial);            /* BYU 2.4.15 */
  400.             CheckItem(myMenus[Emul], EMslip, FALSE);        /* BYU 2.4.15 */
  401.             CheckItem(myMenus[Emul], EMserial, TRUE);        /* BYU 2.4.15 */
  402.                                                             /* BYU 2.4.15 */
  403.         } else {                                            /* BYU 2.4.15 */
  404.                                                             /* BYU 2.4.15 */
  405.             DisableItem ( myMenus[Emul], EMslip);            /* BYU 2.4.15 */
  406.             CheckItem(myMenus[Emul], EMslip, TRUE);            /* BYU 2.4.15 */
  407.             CheckItem(myMenus[Emul], EMserial, FALSE);        /* BYU 2.4.15 */
  408.                                                             /* BYU 2.4.15 */
  409.             i=0;                                                        /* BYU 2.4.15 */
  410.             while((i<numwindows) && (screens[i].connectionType == 0))    /* BYU 2.4.15 */
  411.                 i++;                                                    /* BYU 2.4.15 */
  412.             if (i>= numwindows) {                            /* BYU 2.4.15 */
  413.                 EnableItem (myMenus[Emul], EMserial);        /* BYU 2.4.15 */
  414.             } else {                                        /* BYU 2.4.15 */
  415.                 DisableItem (myMenus[Emul], EMserial);        /* BYU 2.4.15 */
  416.             }                                                /* BYU 2.4.15 */
  417.         }                                                    /* BYU 2.4.15 */
  418.                                                             /* BYU 2.4.15 */
  419.     } else {                                                /* BYU 2.4.15 */
  420.         DisableItem ( myMenus[Emul],EMslip);                /* BYU 2.4.15 */
  421.         DisableItem ( myMenus[Emul],EMserial);                /* BYU 2.4.15 */
  422.         if (slip_connection) {                                /* BYU 2.4.16 */
  423.             CheckItem(myMenus[Emul], EMslip, TRUE);            /* BYU 2.4.16 */
  424.             CheckItem(myMenus[Emul], EMserial, FALSE);        /* BYU 2.4.16 */
  425.         } else {                                            /* BYU 2.4.16 */
  426.             CheckItem(myMenus[Emul], EMslip, FALSE);        /* BYU 2.4.16 */
  427.             CheckItem(myMenus[Emul], EMserial, TRUE);        /* BYU 2.4.16 */
  428.         }                                                    /* BYU 2.4.16 */
  429.     }                                                        /* BYU 2.4.15 */
  430. }                                                            /* BYU 2.4.15 */
  431.  
  432. void AdjustMenus
  433.   (
  434.     void
  435.   )
  436. {
  437.     int i;
  438.  
  439.     if ((i=portsOpen()) <1) {
  440.         DisableItem( myMenus[Fil],FLclose);
  441.         DisableItem( myMenus[Fil],FLsave);
  442.         DisableItem( myMenus[Fil],FLprint);
  443. #ifdef CANTQUIT
  444.     EnableItem ( myMenus[Fil],FLquit);
  445. #endif
  446.         DisableItem( myMenus[Edit],EDcut);
  447.         DisableItem( myMenus[Edit],EDundo);
  448.         DisableItem( myMenus[Edit],EDclear);
  449.         DisableItem( myMenus[Edit],EDcopy);
  450.         DisableItem( myMenus[Edit],EDcopyt);
  451.  
  452.  
  453.         DisableItem( myMenus[Emul],EMbs);
  454.         DisableItem( myMenus[Emul],EMdel);
  455.         DisableItem( myMenus[Emul],EMecho);
  456.         DisableItem( myMenus[Emul],EMwrap);
  457.         DisableItem( myMenus[Emul],EMscroll);
  458.         DisableItem( myMenus[Emul],EMreset);
  459.         DisableItem ( myMenus[Emul],EMjump);
  460.         DisableItem ( myMenus[Emul],EMpage);
  461.         DisableItem ( myMenus[Emul],EMclear);    /* BYU 2.4.14 */
  462.         DisableItem ( myMenus[Emul],EMlines);
  463.         DisableItem ( myMenus[Emul],EMsetup);
  464.         DisableItem ( myMenus[Emul],EMfont);
  465.         DisableItem ( myMenus[Emul],EMsize);
  466.         DisableItem ( myMenus[Emul],EMcolor);
  467.         DisableItem ( myMenus[Emul],EMslip);    /* BYU 2.4.15 */
  468.         DisableItem ( myMenus[Emul],EMserial);    /* BYU 2.4.15 */
  469.         DisableItem ( myMenus[Emul],EMcapture);    /* BYU 2.4.18 */
  470.  
  471.         DisableItem( myMenus[Net ],NEftp);
  472.         DisableItem( myMenus[Net ],NEip);
  473.         DisableItem( myMenus[Net ],NEayt);
  474.         DisableItem( myMenus[Net ],NEao);
  475.         DisableItem( myMenus[Net ],NEinter);
  476.         DisableItem( myMenus[Net ],NEec);
  477.         DisableItem( myMenus[Net ],NEel);
  478.         DisableItem( myMenus[Net ],NEscroll);
  479.         if (userlevel==0 ) 
  480.             EnableItem( myMenus[Net], NEconfig);
  481.  
  482.         if (i<0) {
  483.             EnableItem ( myMenus[Fil ],FLclose);
  484.             }
  485.         if (ScrlLock) {
  486.             ScrlLock=0;
  487.             CheckItem(myMenus[Net ], NEscroll,FALSE);
  488.             }
  489.         } 
  490.     else {
  491.         EnableItem ( myMenus[Fil],FLclose);
  492.         EnableItem ( myMenus[Fil],FLsave);
  493.  
  494. /*        EnableItem ( myMenus[Fil],FLprint); */
  495.  
  496. #ifdef CANTQUIT
  497.         DisableItem( myMenus[Fil],FLquit);
  498. #endif
  499.  
  500.         EnableItem ( myMenus[Emul],EMbs);
  501.         EnableItem ( myMenus[Emul],EMdel);
  502.         EnableItem ( myMenus[Emul],EMecho);
  503.         EnableItem ( myMenus[Emul],EMwrap);
  504.         EnableItem ( myMenus[Emul],EMscroll);
  505.         EnableItem ( myMenus[Emul],EMreset);
  506.         EnableItem ( myMenus[Emul],EMjump);
  507.         EnableItem ( myMenus[Emul],EMpage);
  508.         EnableItem ( myMenus[Emul],EMclear);    /* BYU 2.4.14 */
  509.         EnableItem ( myMenus[Emul],EMlines);
  510.         EnableItem ( myMenus[Emul],EMsetup);
  511.         EnableItem ( myMenus[Emul],EMfont);
  512.         EnableItem ( myMenus[Emul],EMsize);
  513.         EnableItem ( myMenus[Emul],EMcapture);    /* BYU 2.4.18 */
  514.  
  515.         if (HasColor) 
  516.             EnableItem ( myMenus[Emul],EMcolor);
  517.     
  518.         EnableItem ( myMenus[Net ],NEftp);
  519.         EnableItem ( myMenus[Net ],NEip);
  520.         EnableItem ( myMenus[Net ],NEayt);
  521.         EnableItem ( myMenus[Net ],NEao);
  522.         EnableItem ( myMenus[Net ],NEinter);
  523.         EnableItem ( myMenus[Net ],NEec);
  524.         EnableItem ( myMenus[Net ],NEel);
  525.         EnableItem ( myMenus[Net ],NEscroll);
  526.         if (EtherNet == -99)
  527.             EnableItem( myMenus[Net ],NEconfig);
  528.         else
  529.             DisableItem( myMenus[Net ],NEconfig);
  530.     }
  531.  
  532.     SLIP_menus();                                /* BYU 2.4.15 */
  533. }
  534.  
  535. /*
  536.  *    switchMenus( which) - Switch from our current menus to the key menus (1)
  537.  *                          or the normal menus (0).
  538.  */
  539.  
  540. void switchMenus
  541.   (
  542.     int which
  543.   )
  544. {
  545.     int i;
  546.  
  547.     DeleteMenu( fileMenu);                    /* Take them from the menu bar */
  548.     DeleteMenu( editMenu);
  549.     DeleteMenu( termMenu);
  550.     DeleteMenu(  netMenu);
  551.  
  552.     if (which) {
  553.         myMenus[Fil ] = GetMenu(NfileMenu);
  554.         myMenus[Edit] = GetMenu(NeditMenu);
  555.         myMenus[Emul] = GetMenu(NtermMenu);
  556.         myMenus[Net ] = GetMenu(NnetMenu );
  557.         DelMenuItem(myMenus[Conn],1);
  558.         InsMenuItem(myMenus[Conn],"\017Next Session/N\0",0);
  559.         ctrl = optionKey;                    /* Option key is the control key.... */
  560.         }
  561.     else {
  562.         myMenus[Fil ] = GetMenu(fileMenu);
  563.         myMenus[Edit] = GetMenu(editMenu);
  564.         myMenus[Emul] = GetMenu(termMenu);
  565.         myMenus[Net ] = GetMenu( netMenu);
  566.         DelMenuItem(myMenus[Conn],1);
  567.         InsMenuItem(myMenus[Conn],"\015Next Session\0",0);
  568.  
  569.         ctrl = cmdKey;                        /* Command key is the control key... */
  570.         }
  571.  
  572.     for(i=1; i<Conn; i++)
  573.         InsertMenu( myMenus[i], connMenu);    /* Put them in the menu bar */
  574.  
  575.     AdjustMenus();            /* Hilite the right stuff */
  576.  
  577.     if (MacBinary)
  578.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  579.     else
  580.         CheckItem(myMenus[Fil],FLbin,FALSE);
  581.  
  582.     if (ftpavail) 
  583.         CheckItem(myMenus[Fil],FLftp,TRUE);        /* Check ftpavail ... */
  584.     else
  585.         CheckItem(myMenus[Fil],FLftp,FALSE);
  586.  
  587.     if (ftplogon)
  588.         CheckItem(myMenus[Fil],FLlog,TRUE);        /* and the log .... */
  589.     else
  590.         CheckItem(myMenus[Fil],FLlog,FALSE);
  591.  
  592.     if (ScrlLock)                                 /* and the Suspend network ... */
  593.         CheckItem(myMenus[Net], NEscroll,TRUE);
  594.     else 
  595.         CheckItem(myMenus[Net], NEscroll,FALSE);
  596.  
  597.     if (numwindows>0)                            /* and set the BSDEL flag */
  598.         CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,FALSE);
  599.  
  600. /*    SLIP_menus();                                /* BYU 2.4.15 */
  601.  
  602.     DrawMenuBar();                                /* Draw what we have done */
  603.  
  604.     SLIP_menus();                                /* BYU 2.4.18 */
  605.  
  606.     if (userlevel!=0) 
  607.         DisableItem( myMenus[Net], NEconfig);
  608.     if (!HasColor)
  609.         DisableItem( myMenus[Emul], EMcolor);
  610.  
  611. }
  612.  
  613. /*
  614.  *    setupmenu - Set up (load) all menus and prepare menu bar.
  615.  *                set default check marks.
  616.  */
  617.  
  618. void setupmenu
  619.   (
  620.     int def
  621.   )
  622. {
  623.     int i;
  624.     char temp[256];
  625.  
  626.     ftpavail = Sfmode();                        /* Get the FTP Mode from session layer */
  627.     for (i=0; i<150; i++) stupidarray[i]='W';    /* Set up the width array */
  628.     myMenus[0] = GetMenu(appleMenu);                /* Get all of our friendly menus */
  629.     myMenus[Conn] = GetMenu(connMenu);
  630.     myMenus[Font] = GetMenu(fontMenu);
  631.     myMenus[Size] = GetMenu(sizeMenu);
  632.  
  633.     AddResMenu(myMenus[0], 'DRVR');                    /* Add in the DA's */
  634.  
  635.     InsertMenu(myMenus[0], 0);                        /* Insert the Menus into the bar */
  636.     InsertMenu(myMenus[Conn], 0);
  637.     InsertMenu(myMenus[Font], -1);
  638.     InsertMenu(myMenus[Size], -1);
  639.     
  640.  
  641.     AddResMenu(myMenus[Font], 'FONT');                /* Put the fonts in the font menu */
  642.  
  643.     nFontNumber = i = CountMItems( myMenus[Font]);    /* Initialize the FontNumber[] array*/
  644.     (Ptr) FontNumber = NewPtr( sizeof(short) *(i+1));
  645.     for (;i>0;i--) {
  646.         getitem( myMenus[Font], i, temp);    
  647.         getfnum( temp, &FontNumber[i]);                    /* With the font numbers */
  648.         }
  649.  
  650.     nFontSize = i = CountMItems( myMenus[Size]);     /* Initialize the FontSize[] array */
  651.     (Ptr) FontSize = NewPtr( sizeof(int) *(i+1));
  652.     for (;i>0;i--) {
  653.         getitem( myMenus[Size], i, temp);
  654. #ifndef MPW
  655.         ptoc(temp);
  656. #endif MPW
  657.         sscanf( temp, "%d", &FontSize[i]);                /* Read from the resource itself */
  658.         }
  659.  
  660.     FontNumber[0]=0;
  661.     FontSize[0]=0;
  662.  
  663.     switchMenus(def);
  664. }
  665.  
  666.  
  667. /*
  668.  *    updateMenuChecks() - update the check marks for file transfer
  669.  *                         (MacBinary and ftpavail)
  670.  */
  671.  
  672. void updateMenuChecks
  673.   (
  674.     void
  675.   )
  676. {
  677.     if (MacBinary)
  678.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  679.     else
  680.         CheckItem(myMenus[Fil],FLbin,FALSE);
  681.  
  682.     ftpavail = Sfmode();
  683.     if (ftpavail) 
  684.         CheckItem(myMenus[Fil],FLftp,TRUE);        /* Check ftpavail ... */
  685.     else
  686.         CheckItem(myMenus[Fil],FLftp,FALSE);
  687. }
  688.  
  689. /*
  690.  *    DisplayMacBinary()    - Sets the macbinary check mark according to the 
  691.  *                          MacBinary flag 
  692.  */
  693.  
  694. void DisplayMacBinary
  695.   (
  696.     void
  697.   )
  698. {
  699.     if (MacBinary)
  700.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  701.     else
  702.         CheckItem(myMenus[Fil],FLbin,FALSE);
  703. }
  704.  
  705. /*
  706.  *     CheckFonts()        - Place checkmarks and outlines on the appropriate
  707.  *                          menu items for the fonts 
  708.  */
  709.  
  710. CheckFonts()
  711. {
  712.     int i, fsiz, fnum;
  713.  
  714.     RSgetfont( screens[scrn].vs, &fnum, &fsiz);
  715.  
  716.     for(i=1; i<=nFontNumber;i++)
  717.         if (fnum == FontNumber[i])                        /* Check Our Current Font */
  718.             CheckItem( myMenus[Font], i, TRUE);
  719.         else
  720.             CheckItem( myMenus[Font], i, FALSE);
  721.  
  722.     for(i=1; i<=nFontSize;i++) {
  723.         if (fsiz == FontSize[i])
  724.             CheckItem( myMenus[Size], i, TRUE);            /* Check Our Current Size */
  725.         else
  726.             CheckItem( myMenus[Size], i, FALSE);
  727.  
  728.         if (RealFont( fnum, FontSize[i]))                /* Outline All Available REAL Sizes */
  729.             SetItemStyle( myMenus[Size], i, 8);
  730.         else
  731.             SetItemStyle( myMenus[Size], i, 0);
  732.         }
  733. }
  734.  
  735. /*
  736.  *    applAbout - display the about dialog for the application.
  737.  *        Displays until clicked on.
  738.  */
  739. void applAbout
  740.   (
  741.     void
  742.   )
  743. {
  744.     DialogPtr About;
  745.     short itemhit;
  746.  
  747.     About=GetNewDialog( 501, (Ptr) 0L,(WindowPtr) -1L);
  748.     if (About) {
  749.         ModalDialog((ModalFilterProcPtr) modalProc, &itemhit);
  750.         DisposDialog(About);
  751.         }
  752.  
  753.     About=GetNewDialog( 256, (Ptr) 0L,(WindowPtr) -1L);
  754.     UItemAssign( About, 2, (int (*)()) VersionNumber);
  755.     ModalDialog((ModalFilterProcPtr) modalProc, &itemhit);
  756.     DisposDialog(About);
  757.     
  758. }
  759.  
  760. /*
  761.  *    configport -    Used to reconfigure a session
  762.  */
  763.  
  764. int configport
  765.   (
  766.     ConfigRec *config
  767.   )
  768. {
  769.     /*  struct machinfo *mp;  */
  770.     DialogPtr dtemp;
  771.     int SBon=1, Del=1, width=80, tek=1,cr=1,echo=1,tektype,line,eightbit;    /* BYU 2.4.9 */
  772.     short dItem;
  773.     Str255 temps,*tempp;
  774.     Rect dBox;
  775.     Handle host,name,scrlon,scrlnum,kbbs,kbdel,w132,w80,tekclear,tekcreate,
  776.             crLF, crNUL,echoBuff,echoSend,tekold,teknew,lineyes,lineno,        /* BYU 2.4.9 */
  777.             eightyes,eightno;                                                /* BYU 2.4.9 */
  778.  
  779.     Handle tekDis;                            /* NCSA 2.5 */
  780.     
  781.     SetCursor(normcurs);
  782.     
  783.     SBon=config->scrollback>0;
  784.     Del=config->bsdel;
  785.     width= config->width;
  786.     tek= config->tekclear;
  787.     cr = config->crmap == 10;
  788.     echo =  !config->halfdup;
  789.     tektype = config->tektype;
  790.     line = config->lineAllow;
  791.     eightbit = config->eightbit;    /* BYU 2.4.9 */
  792.     
  793.     tempp = (Str255 *) temps;
  794.     dtemp=GetNewDialog( SConfigDLOG,(Ptr) 0L,(WindowPtr) -1L);    /* Bring on the box */
  795.     UItemAssign( dtemp, 25, (int (*)()) OutlineItem);
  796.  
  797. #ifndef MPW
  798.     config->machine=ctop(config->machine);
  799. #endif MPW
  800.  
  801.     GetDItem( dtemp, SChost, &dItem, &host, &dBox);    /* Install the default host */
  802.     setitext( host , config->machine);
  803.  
  804.     GetDItem( dtemp, SCname, &dItem, &name, &dBox);    /* Install the default name */
  805.     setitext( name, config->name);                    /* Here is default */
  806.     SelIText( dtemp, SCname, 0, 32767);                /* And select it... */
  807.  
  808.     GetDItem( dtemp, SCscrolnum, &dItem, &scrlnum, &dBox);    /* Default Scrollback */
  809.     sprintf((char *) tempp, "%d", SBon?config->scrollback:120);
  810. #ifndef MPW
  811.     ctop(tempp);
  812. #endif MPW
  813.     setitext( scrlnum, (char *) tempp);    
  814.  
  815.     GetDItem( dtemp, SCscrolon, &dItem, &scrlon, &dBox);        /* Get all of the handles now */
  816.     GetDItem( dtemp, SCkbbs, &dItem, &kbbs, &dBox);
  817.     GetDItem( dtemp, SCkbdel, &dItem, &kbdel, &dBox);
  818.     GetDItem( dtemp, SCwidth132, &dItem, &w132, &dBox);
  819.     GetDItem( dtemp, SCwidth80, &dItem, &w80, &dBox);
  820.     GetDItem( dtemp, SCtekclear, &dItem, &tekclear, &dBox);
  821.     GetDItem( dtemp, SCtekcreate, &dItem, &tekcreate, &dBox);
  822.     GetDItem( dtemp, SCcrLF, &dItem, &crLF, &dBox);
  823.     GetDItem( dtemp, SCcrNUL, &dItem, &crNUL, &dBox);
  824.     GetDItem( dtemp, SCechoBuff, &dItem, &echoBuff, &dBox);
  825.     GetDItem( dtemp, SCechoSend, &dItem, &echoSend, &dBox);
  826.     GetDItem( dtemp, SCtekold, &dItem, &tekold, &dBox);
  827.     GetDItem( dtemp, SCteknew, &dItem, &teknew, &dBox);
  828.     GetDItem( dtemp, SClineY, &dItem, &lineyes, &dBox);
  829.     GetDItem( dtemp, SClineN, &dItem, &lineno, &dBox);
  830.     GetDItem( dtemp, SCeightY, &dItem, &eightyes, &dBox);    /* BYU 2.4.9 */
  831.     GetDItem( dtemp, SCeightN, &dItem, &eightno, &dBox);    /* BYU 2.4.9 */
  832.     GetDItem( dtemp, SCtekdis, &dItem, &tekDis, &dBox);    /* NCSA 2.5 */
  833.  
  834. /*    HiliteControl(w132, 255); */
  835.  
  836.     SetCtlValue((ControlHandle) scrlon, SBon);
  837.     SetCtlValue((ControlHandle) kbdel, Del);
  838.     SetCtlValue((ControlHandle) kbbs, !Del);
  839.     SetCtlValue((ControlHandle) w132, (width==132));
  840.     SetCtlValue((ControlHandle) w80, !(width==132));
  841.     SetCtlValue((ControlHandle) tekcreate, !tek);
  842.     SetCtlValue((ControlHandle) tekclear ,  tek);
  843.     SetCtlValue((ControlHandle) crLF ,  cr);
  844.     SetCtlValue((ControlHandle) crNUL, !cr);
  845.     SetCtlValue((ControlHandle) echoBuff,  echo);
  846.     SetCtlValue((ControlHandle) echoSend,  !echo);
  847.     SetCtlValue((ControlHandle) tekold,  (tektype== 0));    /* NCSA 2.5 */
  848.     SetCtlValue((ControlHandle) teknew,  (tektype== 1));    /* NCSA 2.5 */
  849.     SetCtlValue((ControlHandle) tekDis,  (tektype== -1));    /* NCSA 2.5 */
  850.     SetCtlValue((ControlHandle) lineyes,  line);
  851.     SetCtlValue((ControlHandle) lineno,  !line);
  852.     SetCtlValue((ControlHandle) eightyes,  eightbit);    /* BYU 2.4.9 */
  853.     SetCtlValue((ControlHandle) eightno,  !eightbit);    /* BYU 2.4.9 */
  854.  
  855.  
  856.     dItem=0;                                /* initially no hits */
  857.     while((dItem>2) || (dItem==0)) {        /* While we are in the loop */
  858.         ModalDialog((ModalFilterProcPtr)modalProc,&dItem); /* and do our duty to the box */
  859.         switch( dItem) {
  860.             case SCscrolon:
  861.                 SBon=!SBon;
  862.                 SetCtlValue((ControlHandle) scrlon, SBon);
  863.                 break;
  864.             case SCkbbs:
  865.                 Del=0;
  866.                 SetCtlValue((ControlHandle) kbbs, !Del);
  867.                 SetCtlValue((ControlHandle) kbdel, Del);
  868.                 break;
  869.             case SCkbdel:
  870.                 Del=1;
  871.                 SetCtlValue((ControlHandle) kbdel, Del);
  872.                 SetCtlValue((ControlHandle) kbbs, !Del);
  873.                 break;
  874.             case SCwidth132:
  875.                 width=132;
  876.                 SetCtlValue((ControlHandle) w132, (width==132));
  877.                 SetCtlValue((ControlHandle) w80,  (width!=132));
  878.                 break;
  879.             case SCwidth80:
  880.                 width=80;
  881.                 SetCtlValue((ControlHandle) w132, (width==132));
  882.                 SetCtlValue((ControlHandle) w80,  (width!=132));
  883.                 break;
  884.             case SCtekclear:
  885.                 tek=1;
  886.                 SetCtlValue((ControlHandle) tekcreate, !tek);
  887.                 SetCtlValue((ControlHandle) tekclear ,  tek);
  888.                 break;
  889.             case SCtekcreate:
  890.                 tek=0;
  891.                 SetCtlValue((ControlHandle) tekcreate, !tek);
  892.                 SetCtlValue((ControlHandle) tekclear ,  tek);
  893.                 break;
  894.             case SCcrLF:
  895.                 cr=1;
  896.                 SetCtlValue((ControlHandle) crLF ,  cr);
  897.                 SetCtlValue((ControlHandle) crNUL, !cr);
  898.                 break;
  899.             case SCcrNUL:
  900.                 cr=0;
  901.                 SetCtlValue((ControlHandle) crLF ,  cr);
  902.                 SetCtlValue((ControlHandle) crNUL, !cr);
  903.                 break;
  904.             case SCechoBuff:
  905.                 echo=1;
  906.                 SetCtlValue((ControlHandle) echoBuff,  echo);
  907.                 SetCtlValue((ControlHandle) echoSend,  !echo);
  908.                 break;
  909.             case SCechoSend:
  910.                 echo=0;
  911.                 SetCtlValue((ControlHandle) echoBuff,  echo);
  912.                 SetCtlValue((ControlHandle) echoSend,  !echo);
  913.                 break;
  914.             case SCtekold:
  915.                 tektype=0;
  916.                 SetCtlValue((ControlHandle) tekold,  !tektype);
  917.                 SetCtlValue((ControlHandle) teknew,  (tektype==1));    /* NCSA 2.5 */
  918.                 SetCtlValue((ControlHandle) tekDis,  0);    /* NCSA 2.5 */
  919.                 break;
  920.             case SCteknew:
  921.                 tektype=1;
  922.                 SetCtlValue((ControlHandle) tekold,  !tektype);
  923.                 SetCtlValue((ControlHandle) teknew,  (tektype==1));
  924.                 SetCtlValue((ControlHandle) tekDis,  0);    /* NCSA 2.5 */
  925.                 break;
  926.             case SCtekdis:                                        /* NCSA 2.5 */
  927.                 tektype= -1;                                    /* NCSA 2.5 */
  928.                 SetCtlValue((ControlHandle) tekold,  !tektype);    /* NCSA 2.5 */
  929.                 SetCtlValue((ControlHandle) teknew,  (tektype==1));    /* NCSA 2.5 */
  930.                 SetCtlValue((ControlHandle) tekDis, 1);            /* NCSA 2.5 */
  931.                 break;                                            /* NCSA 2.5 */
  932.             case SClineY:
  933.                 line=1;
  934.                 SetCtlValue((ControlHandle) lineyes,  line);
  935.                 SetCtlValue((ControlHandle) lineno,  !line);
  936.                 break;
  937.             case SClineN:
  938.                 line=0;
  939.                 SetCtlValue((ControlHandle) lineyes,  line);
  940.                 SetCtlValue((ControlHandle) lineno,  !line);
  941.                 break;
  942.             case SCeightY:                                            /* BYU 2.4.9 */
  943.                 eightbit=1;                                            /* BYU 2.4.9 */
  944.                 SetCtlValue((ControlHandle) eightyes,  eightbit);    /* BYU 2.4.9 */
  945.                 SetCtlValue((ControlHandle) eightno,  !eightbit);    /* BYU 2.4.9 */
  946.                 break;                                                /* BYU 2.4.9 */
  947.             case SCeightN:                                            /* BYU 2.4.9 */
  948.                 eightbit=0;                                            /* BYU 2.4.9 */
  949.                 SetCtlValue((ControlHandle) eightyes,  eightbit);    /* BYU 2.4.9 */
  950.                 SetCtlValue((ControlHandle) eightno,  !eightbit);    /* BYU 2.4.9 */
  951.                 break;                                                /* BYU 2.4.9 */
  952.             }
  953.         }
  954.  
  955.     if (dItem==DLOGCancel) {
  956.             DisposDialog( dtemp);
  957.             updateCursor(1);
  958.             return(0);
  959.             }
  960.  
  961.     getitext( host, config->machine);            /* where do we go from here? */
  962.     getitext( name, config->name);                /* And what is its name ...  */
  963.     if ( *config->name == 0 ) {
  964.         getitext( host, config->name);            /* Copy the host name in ... */
  965.         }
  966.     getitext( scrlnum, (char *) tempp);            /* here is our ascii number */
  967.  
  968. #ifndef MPW
  969.     tempp= (Str255 *)ptoc(tempp);
  970. #endif
  971.  
  972.     DisposDialog( dtemp);
  973.     updateCursor(1);
  974.  
  975. #ifndef MPW 
  976.     config->machine=ptoc(config->machine);
  977. #endif
  978.  
  979.     config->scrollback=120;            /* Make certain that number will be valid */
  980.     if ( SBon) {
  981.             if (sscanf((char *) tempp, "%d", &config->scrollback) !=1) {
  982.                 config->scrollback=0;
  983.                 SBon = 0;
  984.                 }
  985.             }
  986.     else
  987.         config->scrollback=0;
  988.     config->lineAllow=line;
  989.     config->eightbit=eightbit;        /* BYU 2.4.9 */
  990.     config->bsdel=Del;
  991.     config->tektype=tektype;
  992.     config->width=width;
  993.     config->tekclear=tek;
  994.     config->halfdup= !echo;
  995.     if (cr)
  996.         config->crmap= 0x0a;
  997.     else 
  998.         config->crmap= 0x00;
  999.  
  1000.     return(1);
  1001. } /* configport */
  1002.  
  1003.  
  1004.  
  1005. pascal Boolean  theProc(theDialog,theEvent,theItem)
  1006.     DialogPtr theDialog;
  1007.     EventRecord *theEvent;
  1008.     short *theItem;
  1009. {
  1010.     int    ascii;
  1011.     OSErr err;
  1012.     
  1013.     
  1014.     if (theEvent->what==keyDown || theEvent->what==autoKey)
  1015.         {
  1016.         ascii = theEvent->message & charCodeMask;
  1017.         if (ascii==CR || ascii==3) 
  1018.             {
  1019.             *theItem = 1;
  1020.             return 1;
  1021.             }
  1022.  
  1023.         if (theEvent->modifiers & cmdKey && theEvent->modifiers&shiftKey)
  1024.             if (ascii=='.')
  1025.                 {
  1026.                 *theItem =2;
  1027.                 return 1;
  1028.                 }
  1029.  
  1030.         if (theEvent->modifiers&cmdKey)
  1031.             {
  1032.             switch (ascii)
  1033.                 {
  1034.             
  1035.                 case 'v':    err=TEFromScrap();
  1036.                         DlgPaste(theDialog);
  1037.                         /*TEPaste(myDPeek.textH);*/
  1038.                         *theItem=5;
  1039.                         return 1;
  1040.                         break;
  1041.                 case 'c':
  1042.                         DlgCopy(theDialog);
  1043.                         ZeroScrap();
  1044.                         err=TEToScrap();
  1045.                         *theItem=5;
  1046.                         return 1;
  1047.                         break;
  1048.                 case 'x': 
  1049.                         DlgCut(theDialog);
  1050.                         ZeroScrap();
  1051.                         err=TEToScrap();
  1052.                         *theItem=5;
  1053.                         return 1;
  1054.                         break;            
  1055.                 }
  1056.             }
  1057.             
  1058.  
  1059.         if (theEvent->modifiers & ( optionKey | controlKey | cmdKey)) 
  1060.             {
  1061.             SysBeep(1);
  1062.             *theItem=5;
  1063.             return 1;
  1064.             }            
  1065.  
  1066.         if (isalnum(ascii) || (ascii=='.') || (ascii=='-') || (ascii==BS) || (ascii==' ') || (ascii==TAB));     
  1067.             return 0;
  1068.  
  1069.  
  1070.         SysBeep(1);
  1071.         *theItem=5;
  1072.         return 1;
  1073.         }
  1074.     return 0;
  1075. }
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082. /*
  1083.  *    setupport -    Used to start a session
  1084.  */
  1085.  
  1086. void setupport(theFtpFlag)
  1087.     short theFtpFlag;
  1088.     
  1089. {
  1090.     short cc;
  1091.     DialogPtr dtemp;
  1092.     ConfigRec config;
  1093.     int ftponly,oldscrn,serialonly;        /* BYU 2.4.15 */
  1094.     short dItem,myDitem;
  1095.     Str255 temps,*tempp;
  1096.     Rect dBox,myRect;
  1097.     Handle sessiontype,host,name,myHandle,okHandle;        /* BYU 2.4.15 */
  1098.     static numWind=1;
  1099.     char aTempStr[4];
  1100.     register short i;
  1101.     AliasRecord theAliasRec;            /* NCSA: data for this alias */
  1102.  
  1103.     /* struct machinfo *mp; */
  1104.  
  1105.     tempp = (Str255 *) temps;
  1106.  
  1107.     configdefault( &config);                    /* Start with the lowest of the low */
  1108.     if (theFtpFlag) config.ftpwind = 1;
  1109.     
  1110.     { char *p;
  1111.     if (NULL == (p = NewPtr(40000))) {            /* do we have enough memory? */
  1112.     
  1113. #ifndef MPW
  1114.         OtherError("\PNo memory for connnection","\P ");
  1115. #else
  1116.         OtherError("Not enough memory left to open"," ");
  1117. #endif MPW
  1118.         return;
  1119.         }
  1120.     else
  1121.         DisposPtr(p);
  1122.     }
  1123.  
  1124.     config.name=NewPtr(256);                    /* Get some space for our name */
  1125.     config.machine=NewPtr(256);                    /* Get some space for our name */
  1126.     for (cc=0;cc<255;cc++)
  1127.             config.machine[cc] =0;
  1128.  
  1129.     dtemp=GetNewDialog( SessionDLOG,(Ptr) myDPeek,(WindowPtr) -1L);    /* Bring on the box */
  1130.      UItemAssign( dtemp, 8, (int (*)()) OutlineItem); 
  1131.  
  1132.     SetCursor(normcurs);
  1133.     
  1134.     GetDItem( dtemp, Shost, &dItem, &host, &dBox);    /* Install the default host */
  1135.     setitext( host , (char *) defaultd);
  1136.     SelIText( dtemp, Shost, 0, 32767);                /* And select it... */
  1137.     GetDItem(dtemp,3,&myDitem,&myHandle,&myRect);
  1138.     GetDItem(dtemp,3,&myDitem,&okHandle,&dBox);
  1139.  
  1140.     GetDItem( dtemp, Sname, &dItem, &name, &dBox);    /* Install the default name */
  1141. /*    setitext( name, defaultd);                        No Default */
  1142.  
  1143.  
  1144.     modalItems = 2;        /* BYU 2.4.15 - indicate number of cmd keys active */
  1145.     modalItem[0] = 9;    /* BYU 2.4.15 - enable modal cmd key feature on item 9 */
  1146.     modalKey[0] = 3;    /* BYU 2.4.15 - cmd F key toggles FTP session button */
  1147.     modalItem[1] = 10;    /* BYU 2.4.15 - enable modal cmd key feature on item 10 */
  1148.     modalKey[1] = 1;    /* BYU 2.4.15 - cmd S key toggles Serial session button */
  1149.  
  1150.     ftponly = 0;    /* BYU */
  1151.  
  1152.     if (EtherNet == -100) {                                                /* BYU 2.4.15 */
  1153.         serialonly = 1;                                                    /* BYU 2.4.15 */
  1154.         GetDItem( dtemp, Sserialonly, &dItem, &sessiontype, &dBox);        /* BYU 2.4.15 */
  1155.         SetCtlValue( (ControlHandle) sessiontype, serialonly);            /* BYU 2.4.15 */
  1156.         HiliteControl((ControlHandle) sessiontype, 255);                /* BYU 2.4.15 */
  1157.         if (!slip_connection) {                                            /* BYU 2.4.15 */
  1158.             GetDItem( dtemp, Sftponly, &dItem, &sessiontype, &dBox);    /* BYU 2.4.15 */
  1159.             HiliteControl((ControlHandle) sessiontype, 255);            /* BYU 2.4.15 */
  1160.         }                                                                /* BYU 2.4.15 */
  1161.     } else                                                                /* BYU 2.4.15 */
  1162.         serialonly = 0;                                                    /* BYU 2.4.15 */
  1163.  
  1164.     dItem=0;                                /* initially no hits */
  1165.     getitext( host, config.machine);            /* where do we go from here? */
  1166.  
  1167.  
  1168.  
  1169.     while((dItem>3) || (dItem==0))            /* While we are in the loop */
  1170.         {
  1171.  
  1172.     if (*config.machine == 0) 
  1173.         {
  1174.         HiliteControl((ControlHandle)myHandle,255);                
  1175. /*        HiliteControl((ControlHandle)okHandle,255); */
  1176.         }        
  1177.     else 
  1178.         {
  1179.         HiliteControl((ControlHandle)myHandle,0);
  1180. /*        HiliteControl((ControlHandle)okHandle,0); */
  1181.         }
  1182.  
  1183.         ModalDialog((ModalFilterProcPtr) modalProc,&dItem);        /* BYU - and do our duty to the box */
  1184.         if (dItem == Sftponly && (EtherNet != -100 || slip_connection)) {    /* BYU 2.4.16 */
  1185.             ftponly = 1 - ftponly;                                        /* BYU - Toggle ftp session flag */
  1186.             GetDItem( dtemp, Sftponly, &dItem, &sessiontype, &dBox);    /* BYU serial */
  1187.             SetCtlValue( (ControlHandle) sessiontype, ftponly);                /* BYU serial */
  1188.             if ((slip_connection == 0) && (EtherNet != -100)) {                /* BYU 2.4.15 */
  1189.                 serialonly = 0;                                                /* BYU serial */
  1190.                 GetDItem( dtemp, Sserialonly, &dItem, &sessiontype, &dBox);    /* BYU serial */
  1191.                 SetCtlValue( (ControlHandle) sessiontype, serialonly);        /* BYU serial */
  1192.             }                                                                /* BYU 2.4.15 */
  1193.         } else if (dItem == Sserialonly && EtherNet != -100) {                /* BYU 2.4.16 */
  1194.             serialonly = 1 - serialonly;                                    /* BYU serial */
  1195.             GetDItem( dtemp, Sserialonly, &dItem, &sessiontype, &dBox);        /* BYU serial */
  1196.             SetCtlValue( (ControlHandle) sessiontype, serialonly);            /* BYU serial */
  1197.             if (slip_connection == 0) {                                        /* BYU 2.4.15 */
  1198.                 ftponly = 0;                                                /* BYU serial - Toggle ftp session flag */
  1199.                 GetDItem( dtemp, Sftponly, &dItem, &sessiontype, &dBox);    /* BYU serial */
  1200.                 SetCtlValue( (ControlHandle) sessiontype, ftponly);            /* BYU serial */
  1201.             }                                                                /* BYU 2.4.15 */
  1202.         }                                                                /* BYU serial */
  1203.         getitext( host, config.machine);            /* where do we go from here? */
  1204. #ifdef NOT        if (*config.machine == 0) 
  1205.             {
  1206.             HiliteControl((ControlHandle)myHandle,255);
  1207.                     
  1208.         else 
  1209.             HiliteControl((ControlHandle)myHandle,0);
  1210. #endif
  1211.         }
  1212.  
  1213.     modalItems = 0;        /* BYU serial - disable modal cmd key feature */
  1214.  
  1215.     if (dItem==DLOGCancel) {
  1216.             DisposPtr( config.name);                /* Don't need this if we throw it out */
  1217.             DisposPtr( config.machine);            /* D I T T O ........................ */
  1218.             DisposDialog( dtemp);
  1219.             return;
  1220.             }
  1221.  
  1222.     getitext( host, config.machine);            /* where do we go from here? */
  1223.  
  1224. /* NCSA:    now that we have the name of the host, check to see if it
  1225.              is really just an alias.  If it is, then give us the REAL
  1226.             name, along with the port number tacked on to the end. */
  1227.  
  1228.     if (GetDataFromAlias(config.machine, &theAliasRec) ==1)
  1229.         {
  1230.         char junk[10];
  1231.         
  1232.         strcpy(config.machine,theAliasRec.name);
  1233.         sprintf (junk," %d",theAliasRec.port);
  1234.         strcat(config.machine,junk);
  1235.         }
  1236.  
  1237.     getitext( name, config.name);                /* And what is its name ...  */
  1238.     if ( *config.name == 0 ) {
  1239.         getitext( host, config.name);            /* Copy the host name in ... */
  1240.         sprintf(aTempStr," %i",(int)numWind);
  1241.         strcat(config.name,aTempStr);
  1242.         } 
  1243.  
  1244.     for (i=0;config.machine[i];i++)
  1245.         if (!isprint(config.machine[i])) config.machine[0]=0;
  1246.             
  1247.     if ( *config.machine == 0 && !serialonly) {        /* BYU 2.4.18 */
  1248.             DisposPtr( config.name);                /* Don't need this if we throw it out */
  1249.             DisposPtr( config.machine);            /* D I T T O ........................ */
  1250.             DisposDialog( dtemp);
  1251.             return;
  1252.         }
  1253.     DisposDialog( dtemp);
  1254.  
  1255.     updateCursor(1);
  1256.     
  1257. #ifndef MPW
  1258.     config.machine=ptoc(config.machine);
  1259. #endif
  1260.     primeConfig( &config);
  1261.     if (theFtpFlag) config.ftpwind =1;
  1262.  
  1263.     if (dItem == 3)            /* Reconfigure port if applicable */
  1264.         if (!configport( &config)) {
  1265.             DisposPtr(config.name);
  1266.             DisposPtr(config.machine);
  1267.             return;
  1268.             }
  1269.     config.connectionType = serialonly;            /* BYU 2.4.15 */
  1270.  
  1271.     config.ftpstate = ftponly;        /* BYU */
  1272.     if (ftponly != 0) {                /* BYU */
  1273.         config.halfdup = 1;            /* BYU */
  1274.         }                            /* BYU */
  1275.  
  1276.     putln("Going addport");
  1277.     oldscrn=addport( &config );    /* Make our user window */
  1278.     numWind++;
  1279.     
  1280.     if (oldscrn<0) {
  1281.         DisposPtr(config.name);
  1282.         DisposPtr(config.machine);
  1283.         return;
  1284.         }
  1285. } /* setupport */
  1286.  
  1287. int ReallyClose
  1288.   (
  1289.     int scrn
  1290.   )
  1291. {
  1292.     DialogPtr dtemp;
  1293.     short item;
  1294.  
  1295.     SetCursor(normcurs);
  1296.     
  1297.     paramtext(screens[scrn].name,0L,0L,0L);
  1298.     dtemp = GetNewDialog( CloseDLOG,(Ptr) 0L,(WindowPtr) -1L);
  1299.     UItemAssign( dtemp, 3,(int (*)())  OutlineItem);
  1300.  
  1301.     item = DLOGCancel +1;
  1302.  
  1303.     while (item> DLOGCancel)
  1304.         ModalDialog((ModalFilterProcPtr) modalProc, &item);
  1305.  
  1306.     DisposDialog( dtemp);
  1307.  
  1308.     updateCursor(1);
  1309.     
  1310.     if (item ==DLOGCancel) {
  1311.         return(0);
  1312.         }    
  1313.  
  1314.     return(1);
  1315. }
  1316.  
  1317. void LoadCONF
  1318.   (
  1319.     void
  1320.   )
  1321. {
  1322.     SFReply sfr;
  1323.     long typesok='CONF';
  1324.     Point where;
  1325.  
  1326.     where.h=100;where.v=100;
  1327. #ifndef MPW
  1328.     sfgetfile( pass(where), "\PSet to load:", 0L, 1, &typesok,
  1329.                     0L, &sfr);
  1330. #else
  1331.     sfgetfile( pass(where), "Set to load:", 0L, 1, (SFTypeList) &typesok,
  1332.                     0L, &sfr);
  1333. #endif MPW
  1334.  
  1335.  
  1336.     if (! sfr.good)
  1337.         return;
  1338.  
  1339.     setvol(0L, sfr.vRefNum);
  1340.     p2cstr(&sfr.fName);
  1341.     readconfig(&sfr.fName);
  1342.     setmydir();                /* restore default dir for FTP */
  1343. }
  1344.  
  1345. void SaveCONF
  1346.   (
  1347.     void
  1348.   )
  1349.   {
  1350.     SFReply sfr;
  1351.     FILE *fp;
  1352.     long typesok='CONF';
  1353.     WindowPeek wpeek;
  1354.     Rect rect;
  1355.     Point where;
  1356.     char temp[256];
  1357.     unsigned int red,green,blue;
  1358.     int fnum,fsiz;
  1359.     int i;
  1360.  
  1361.     where.h = 100; where.v = 100;
  1362. #ifndef MPW
  1363.     sfputfile( pass(where), "\PSave Set to:", "\PTelnet Set", 0L, &sfr);
  1364. #else
  1365.     sfputfile( pass(where), "Save Set to:", "Telnet Set", 0L, &sfr);
  1366. #endif
  1367.  
  1368.     if (! sfr.good)
  1369.         return;
  1370.  
  1371.     setvol(0L, sfr.vRefNum);
  1372.     p2cstr(&sfr.fName);
  1373.     create(&sfr.fName, sfr.vRefNum, 'NCSA', 'CONF');
  1374.  
  1375.     
  1376.     fp = fopen(&sfr.fName, "w");
  1377.  
  1378.     if (whichMenus) 
  1379.         fprintf(fp, "commandkeys = yes\015");
  1380.     else
  1381.         fprintf(fp, "commandkeys = no\015");
  1382.  
  1383.     for (i = 0; i < 10; i++)
  1384.       {
  1385.         getmacro(i, temp);
  1386.         if (*temp) 
  1387.             fprintf(fp, "key%d = \"%s\"\015", i, temp);
  1388.       } /* for */
  1389.         
  1390.     for (i = 0; i < numwindows; i++)
  1391.       {
  1392.         int j;
  1393.         j = RSgetfont(screens[i].vs, &fnum, &fsiz);
  1394.         sprintf(temp,"code: %d. Window %d has fnum,fsize = %d, %d",j,i,fnum,fsiz);
  1395.         putln(temp);
  1396.       } /* for */
  1397.  
  1398.     for (i = 0; i < numwindows; i++)
  1399.       {
  1400.         strncpy( temp, screens[i].name, 255);
  1401.         fprintf( fp, "name= \"%s\"\015", ptoc(temp));
  1402.  
  1403.         strncpy( temp, screens[i].machine, 255);
  1404.         fprintf( fp, "host= \"%s\"\015", ptoc(temp));
  1405.  
  1406.         if (screens[i].connectionType == 1)                            /* BYU 2.4.15 */
  1407.             fprintf( fp, "serial= yes\015");                        /* BYU 2.4.15 */
  1408.         else if (screens[i].ftpstate != 0)                            /* BYU 2.4.15 */
  1409.             fprintf( fp, "ftp= yes\015");                            /* BYU mod */
  1410.  
  1411.         fprintf (fp,"port= %d\015",screens[i].portNum);    /* NCSA: save port # */
  1412.  
  1413.         fprintf( fp, "scrollback= %d\015", (screens[i].maxscroll));
  1414.  
  1415.         if (screens[i].bsdel)
  1416.             fprintf( fp, "erase = delete\015");
  1417.         else
  1418.             fprintf( fp, "erase = backspace\015");
  1419.  
  1420.         wpeek = (WindowPeek) screens[i].wind;
  1421.         rect = (*wpeek->contRgn)->rgnBBox;
  1422.  
  1423.         fprintf( fp, "size = {%d,%d,%d,%d}\015", rect.top, rect.left,
  1424.                     rect.bottom, rect.right);
  1425.  
  1426.         fprintf( fp, "vtwidth = %d\015", screens[i].width);
  1427.  
  1428.         if (screens[i].tekclear)
  1429.             fprintf( fp, "tekclear = yes\015");
  1430.         else
  1431.             fprintf( fp, "tekclear = no\015");
  1432.  
  1433.         if (HasColor)
  1434.           {
  1435.             int j;
  1436.             for (j = 0; j < 4; j++)
  1437.               {
  1438.                 RSgetcolor( screens[i].vs, j, &red, &green, &blue);
  1439.                 fprintf( fp, "rgb%d = {%u,%u,%u}\015", j, red, green, blue);
  1440.               } /* for j */
  1441.           } /* if */
  1442.         RSgetfont( screens[i].vs, &fnum, &fsiz);
  1443.         getfontname( fnum, temp);
  1444. #ifndef MPW
  1445.         ptoc(temp);
  1446. #endif
  1447.  
  1448.         fprintf( fp, "font = \"%s\"\015", temp);
  1449.         fprintf( fp, "fsize= %d\015", fsiz);
  1450.         
  1451.         fprintf( fp, "nlines= %d\015", VSgetlines(screens[i].vs));
  1452.         fprintf( fp, "keystop= %d\015", screens[i].TELstop);
  1453.         fprintf( fp, "keygo= %d\015", screens[i].TELgo);
  1454.         fprintf( fp, "keyip= %d\015", screens[i].TELip);
  1455.         fprintf( fp, "crmap= %d\015", screens[i].crmap);        
  1456.         fprintf( fp, "\015");            /* I hate messy files */
  1457.       } /* for i */
  1458.     fclose(fp);
  1459.     setmydir();                            /* restore default dir for FTP */
  1460.   } /* SaveCONF */
  1461.  
  1462. /*************************************************************************/
  1463. /*  Change transfer directory for FTP
  1464. */
  1465.  
  1466. pascal short FileHook
  1467.   (
  1468.     short item,
  1469.     DialogPtr theDialog
  1470.   )
  1471. {
  1472. #pragma unused(theDialog)
  1473.     if(item == 11) {                    /* Set Directory Button */
  1474.             setdir = 1;
  1475.             
  1476.             return(3);        /* pretend we hit cancel, but we didn't */
  1477.         }
  1478.     else if (item == 12 || item == 13)
  1479.         item = 9;            /* these don't count, map to disabled item */
  1480.  
  1481.     return(item);
  1482. }
  1483.  
  1484. /*
  1485.  *    wdset - set the working directory for FTP's
  1486.  */
  1487.  
  1488. int wdset
  1489.   (
  1490.     void
  1491.   )
  1492. {
  1493.     Point where;
  1494.     SFReply reply;
  1495.  
  1496.     where.h=100;where.v=100;
  1497.     setdir = 0;                    /* clear dir found flag */
  1498.     
  1499.     setmydir();
  1500.     sfpgetfile( &where, "Default receive Directory", NULL, -1, NULL,
  1501.         (DlgHookProcPtr) FileHook, &reply, 4001,
  1502.         (ModalFilterProcPtr) modalProc); 
  1503.  
  1504.     if (setdir)                    /* we got a dir */
  1505.         setSFdir();
  1506.     else {
  1507.         if(!reply.good) return(-1);    /* real cancel button got hit */
  1508.         makemydir(reply.vRefNum);        /* chose a file */
  1509.     }
  1510.     return(0);
  1511.   } /* wdset */
  1512.  
  1513. /*
  1514.  * printGraph -    Print the graphics on the current window
  1515.  *        vg - which graphics window to print
  1516.  */
  1517.  
  1518. void printGraph
  1519.   (
  1520.     int dnum            /* Which drawing to print */
  1521.   )
  1522. {
  1523.     int h,v;            /* used for centering (h=horiz. , v=vert.) */
  1524.     int wh,wv;            /* Window horiz and vert */
  1525.     TPrStatus
  1526.         prStatus;        /* Printing status record */
  1527.     Rect prRect;        /* the rectangle to print in */
  1528.     TPPrPort prPort;    /* the printing port */
  1529.     int j;                /* VG identifier for pass-through */
  1530.     
  1531.     SetCursor(normcurs);
  1532.  
  1533.     if (PrJobDialog(prRecHdl)) {            /* Cancel the print if FALSE */
  1534.         prPort=PrOpenDoc(prRecHdl,0L,0L);        /* Open Printer Port */
  1535.             if (PrError() == 0)    {                /* If we can't, then die */
  1536.                 PrOpenPage(prPort, 0L);            /* Open a page */
  1537.  
  1538.                 (*prRecHdl)->prJob.pIdleProc = (PrIdleProcPtr) printsleep;    /* our sleep/cancel*/
  1539.  
  1540.                 prRect=PGRECT;                    /* Get the page rectangle */
  1541.                 h=prRect.right - prRect.left;    /* Get the width */
  1542.                 v=prRect.bottom- prRect.top;    /* Get the height */
  1543.                 if (3*h<4*v) {                    /* Center the little bugger */
  1544.                     wh = h;
  1545.                     wv = (3 * h)/ 4;
  1546.                     }
  1547.                 else {                            /* On the page rectangle */
  1548.                     wv = v;
  1549.                     wh = (4 * v)/ 3;
  1550.                     }
  1551.         
  1552.                 prRect.top  = (v- wv) /2;
  1553.                 prRect.left = (h- wh) /2;
  1554.                 prRect.bottom = prRect.top + wv;
  1555.                 prRect.right = prRect.left + wh;
  1556.  
  1557.                 j=VGnewwin(3,VGgetVS(dnum));        /* NCSA 2.5: fixed the print call */
  1558.                 RGMPsize( &prRect );
  1559.                 VGzcpy( dnum, j);                /* Love dat zm factr */
  1560.                 VGredraw(dnum,j);                /* Copy the picture in i to j */
  1561.                 VGclose(j);                        /* OK, we're done, give it to someone else */
  1562.                 PrClosePage(prPort);            /* Page out.... */
  1563.                 }
  1564.  
  1565.             PrCloseDoc(prPort);                    /* Done with the document */
  1566.             putln("Doc is closed... the printing begins....");
  1567.  
  1568. #if 1                                                                        /* BYU 2.4.20 */
  1569.         if (PrError()==0)                                                    /* BYU 2.4.20 - changed for HP DeskWriter*/
  1570. #else                                                                        /* BYU 2.4.20 */
  1571.         if (((*prRecHdl)->prJob.bJDocLoop == bSpoolLoop) && (PrError()==0))
  1572. #endif                                                                        /* BYU 2.4.20 */
  1573.             PrPicFile(prRecHdl,0L,0L,0L,&prStatus);
  1574.                                     /* Print the spooled file if applicable */
  1575.     }        /* if PrJobDialog */
  1576.     
  1577.     updateCursor(1);
  1578. }
  1579.  
  1580. /*
  1581.  *    printPages(prPort,charh,title, columns) -
  1582.  *            Prints <charh> on the printer through port <prPort> with <title>
  1583.  *            using <columns>.
  1584.  */
  1585. void printPages
  1586.   (
  1587.     TPPrPort prPort,        /* the Printer port */
  1588.     char **charh,
  1589.     Str255 *Title,
  1590.     int columns,
  1591.     int theScreen
  1592.   )
  1593. {
  1594.     char *charp, *start;
  1595.     long charlen,count=0L;
  1596.     int v,h,vloc,scount=0, lines=0, pgcount=1, pgtmplen, maxlines;
  1597.     char pagetemp[20];
  1598.     FMetricRec info;
  1599.     Fixed columnF;
  1600.     int Fheight, Fwidth;
  1601.     int ww;
  1602.  
  1603.     if ( ((*prRecHdl)->prStl.wDev>>8) !=3 ) {
  1604.                     /* Think about this: put def. font in rsrc fork- STR255 */
  1605.         TextFont(4);                        /* MONACO */
  1606.         v=9;
  1607.         }
  1608.     else {
  1609.         TextFont(22);                        /* or courier */
  1610.         v=14;
  1611.         }
  1612.     columnF = FixRatio( columns, 1);
  1613.     TextFont((*(screens[theScreen].wind)).txFont);
  1614.     TextFace((*(screens[theScreen].wind)).txFace);
  1615.     v = (*(screens[theScreen].wind)).txSize;
  1616.  
  1617.     TextSize(v);
  1618.     FontMetrics( &info );
  1619.     Fheight = FixRound( info.ascent + info.descent + info.leading);
  1620.     Fwidth  = FixRound( info.widMax);
  1621.     Fwidth  = CharWidth('W');            /* Re-assign to largest char */
  1622.  
  1623.     v--;
  1624.     ww = TextWidth( stupidarray,0,columns);
  1625.  
  1626.  
  1627.     HLock(charh);
  1628.     start=charp=*charh;
  1629.     charlen= GetHandleSize(charh);
  1630.  
  1631.     h=PGRECT.right - PGRECT.left;    /* Get the width */
  1632.     v=PGRECT.bottom- PGRECT.top;    /* Get the height */
  1633.  
  1634.     maxlines= (v / Fheight) - 2*VMARGINS -1;        /* Get maxlines */
  1635.     vloc= VMARGINS;
  1636.  
  1637.     while (count<charlen) {
  1638.         PrOpenPage(prPort, 0L);        /* Open the Printer Page */
  1639.         (*prRecHdl)->prJob.pIdleProc = (PrIdleProcPtr) printsleep;    /* our netsleep */
  1640.  
  1641.         MoveTo( 0, (VMARGINS-2)*Fheight);
  1642.         drawstring("Session Name: ");
  1643.  
  1644.         drawstring((char *) Title);
  1645.         sprintf(pagetemp, "Page %d", pgcount);
  1646.         pgtmplen=strlen(pagetemp);
  1647.         MoveTo( h-(pgtmplen * Fwidth), (VMARGINS-2)*Fheight);
  1648.         DrawText( pagetemp, 0, pgtmplen);
  1649.         vloc=VMARGINS;
  1650.  
  1651.         while (lines < maxlines && count<charlen) {
  1652.             while ((count<charlen) && (*charp++!='\n')) { count++; scount++; }
  1653.             MoveTo(0,vloc++*Fheight);
  1654.             if (scount>0)
  1655.                 DrawText(start, 0, scount);
  1656.             count++;
  1657.             lines++;
  1658.             scount=0;
  1659.             start=charp;
  1660.             }
  1661.  
  1662.         vloc=VMARGINS;
  1663.         PrClosePage(prPort);        /* Close the Printer page */
  1664.         lines=0;
  1665.         pgcount++;
  1666.         }
  1667.     HUnlock(charh);
  1668. }
  1669.  
  1670. /*
  1671.  * printText -    Print the text selected on the screen 
  1672.  *        vs - which vs to print from
  1673.  */
  1674.  
  1675. void printText
  1676.   (
  1677.     int vs,                /* Which screen to print */
  1678.     Str255 *Title,            /* The title string */
  1679.       int theScreen
  1680.   )
  1681. {
  1682.     char **charh;            /* The character handle */
  1683.     TPrStatus prStatus;        /* Status record */
  1684.     TPPrPort prPort;        /* the Printer port */
  1685.  
  1686.     charh = RSGetTextSel(vs,0);                /* Get the characters to print */
  1687.  
  1688.     if ( charh==0L)
  1689.         return;                /* don't print nothing.... */
  1690.  
  1691.     SetCursor(normcurs);
  1692.     
  1693.     if (PrJobDialog(prRecHdl)) {            /* Cancel the print if FALSE */
  1694.         prPort=PrOpenDoc(prRecHdl,0L,0L);
  1695.             if (PrError() == 0)    {
  1696.                 printPages( prPort, charh, Title, VSmaxwidth(vs),theScreen);
  1697.                                                             /* Draw the text */
  1698.                 }
  1699.             PrCloseDoc(prPort);
  1700.  
  1701.         if (((*prRecHdl)->prJob.bJDocLoop == bSpoolLoop) && (PrError()==0))
  1702.             PrPicFile(prRecHdl,0L,0L,0L,&prStatus); /* Spool the print */
  1703.                                                 /* If necessary..... */
  1704.         }
  1705.     HPurge(charh);                            /* Kill the printed chars */
  1706.     updateCursor(1);
  1707. }
  1708.  
  1709. int ReallyQuit
  1710.   (
  1711.     void
  1712.   )
  1713. {
  1714.     DialogPtr dtemp;
  1715.     short item;
  1716.  
  1717.     SetCursor(normcurs);
  1718.  
  1719.     dtemp = GetNewDialog( QuitDLOG,(Ptr) 0L,(WindowPtr) -1L);
  1720.     UItemAssign( dtemp, 3, (int (*)()) OutlineItem);
  1721.  
  1722.     item = DLOGCancel +1;
  1723.  
  1724.     while (item> DLOGCancel)
  1725.         ModalDialog((ModalFilterProcPtr) modalProc, &item);
  1726.  
  1727.     DisposDialog( dtemp);
  1728.  
  1729.     updateCursor(1);
  1730.     
  1731.     if (item ==DLOGCancel) {
  1732.         return(0);
  1733.         }    
  1734.  
  1735.     return(1);
  1736. }
  1737.  
  1738. void quit
  1739.   (
  1740.     void
  1741.   )
  1742. {
  1743.     if (numwindows>0)
  1744.         return;
  1745.  
  1746.     if (hKCHR)                        /* BYU 2.4.12 */
  1747.         ReleaseResource(hKCHR);        /* BYU 2.4.12 */
  1748.  
  1749.     if (theWorld.systemVersion < 0x0700)    /* BYU 2.4.18 */
  1750.         optionKeysOff();                    /* BYU 2.4.18 */
  1751.  
  1752.     PortClose();        /* BYU serial - make sure serial port is closed */
  1753.     netshut();
  1754.     PrClose();
  1755.     putln("got here\015");            /* BYU 2.4.18 - changed \n to \015 */
  1756.  
  1757.     if (EtherNet == -99)            /* BYU 2.4.16 */
  1758.         CloseResolver();            /* BYU 2.4.16 */
  1759.  
  1760.     close_mb_files();    /* BYU - Don't leave any files open! */
  1761.     done = 1;            /* BYU */
  1762. }
  1763.  
  1764. /* 
  1765.  * copyGraph    - Copy the current graphics screen.
  1766.  *            dnum - the number of the drawing to copy .
  1767.  */
  1768.  
  1769. void copyGraph
  1770.   (
  1771.     int dnum
  1772.   )
  1773. {
  1774.     long tlong;                    /* Temporary Variable */
  1775.     PicHandle tpic;                /* Mental picture of the thing */
  1776.  
  1777.     tpic=RGtoPICT(dnum);            /* Get the picture */
  1778.     tlong=ZeroScrap();                /* Nobody else can live here */
  1779.     HLock((Handle) tpic);                    /* Lock it for Puting */
  1780.     tlong=PutScrap(GetHandleSize((Handle) tpic),'PICT', (Ptr) *tpic);    /* Store as a PICT */
  1781.     HUnlock((Handle) tpic);                    /* Unlock so we can toss it */
  1782.     KillPicture(tpic);                /* Kill the picture..... */
  1783. }                
  1784.  
  1785. /* 
  1786.  * copyText    - Copy the current selection on the virtual screen
  1787.  *            vs - the number of the virtual screen to copy from
  1788.  */
  1789.  
  1790. void copyText
  1791.   (
  1792.     int vs
  1793.   )
  1794. {
  1795.     char **charh;            /* where to store the characters */
  1796.     long tlong;                /* Necessary temporary variable */
  1797.  
  1798.     tlong=ZeroScrap();        /* This Scrap aint big enough for the both of us */
  1799.  
  1800.     charh=RSGetTextSel(vs,0);        /* Get the text selection */
  1801.  
  1802.     if (charh!= (char *)0L && charh!= (char *)-1L) {    /* Can't do anything without characters */
  1803.         HLock(charh);                /* Lock for putting */
  1804.         tlong=PutScrap(GetHandleSize(charh),'TEXT',*charh);
  1805.                                     /* Put it as a TEXT resource */
  1806.         HUnlock(charh);                /* Unlock for disposal */
  1807.         DisposHandle(charh);        /* Kill the chars */
  1808.         }
  1809.     else putln("No characters to copy darn it!");
  1810. }
  1811.  
  1812. /* 
  1813.  * copyTable   - Copy the current selection on the virtual screen
  1814.  *            vs - the number of the virtual screen to copy from
  1815.  */
  1816.  
  1817. void copyTable
  1818.   (
  1819.     int vs
  1820.   )
  1821. {
  1822.     char **charh;            /* where to store the characters */
  1823.     long tlong;                /* Necessary temporary variable */
  1824.  
  1825.     tlong=ZeroScrap();        /* This Scrap aint big enough for the both of us */
  1826.  
  1827.     charh=RSGetTextSel(vs, Prefs.CTthresh);        /* Get the text selection */
  1828.  
  1829.     if (charh>0L) {                    /* Can't do anything without characters */
  1830.         HLock(charh);                /* Lock for putting */
  1831.         tlong=PutScrap(GetHandleSize(charh),'TEXT',*charh);
  1832.                                     /* Put it as a TEXT resource */
  1833.         HUnlock(charh);                /* Unlock for disposal */
  1834.         DisposHandle(charh);        /* Kill the chars */
  1835.         }
  1836.     else putln("No characters to copy darn it!");
  1837. }
  1838.  
  1839. /*
  1840.  *    paste - Paste the resource from the scrap into the current WIND, if
  1841.  *            and only if it is really text
  1842.  */
  1843.  
  1844. void paste
  1845.   (
  1846.     void
  1847.   )
  1848. {
  1849.     long
  1850. #ifndef MPW
  1851.         GetScrap(),            /* We must cast the Brother */
  1852. #endif
  1853.         off,                /* offset */
  1854.         length;                /* the lenght of what is on the Scrap */
  1855.  
  1856.     /* Flush the buffer if we have echo */
  1857.     
  1858.     if ((screens[scrn].ftpstate == 0) &&    /* BYU */
  1859.         screens[scrn].echo &&                 /* BYU */
  1860.         screens[scrn].kblen>0) {            /* BYU */
  1861.         netwrite( screens[scrn].port, screens[scrn].kbbuf,
  1862.                     screens[scrn].kblen);    /* if full send buffer */
  1863.         screens[scrn].kblen=0;
  1864.         }
  1865.  
  1866.     if (GetScrap(0L, 'TEXT', &off)<=0L)        /* If there are no TEXT res's */
  1867.             { putln("No text on scrap");
  1868.             return;                        /* then we can't paste it */
  1869.             }
  1870.  
  1871.     screens[scrn].outhand=NewHandle(0L);    /* create a handle to put chars in */
  1872.  
  1873.     length= GetScrap( screens[scrn].outhand, 'TEXT',&off);
  1874.                                             /* Store the scrap into the handle */
  1875.     screens[scrn].outlen = length;            /* Set the length */
  1876.     HLock(screens[scrn].outhand);            /* Lock the Handle down for safety */
  1877.     screens[scrn].outptr=*screens[scrn].outhand;    /* Set the pointer */
  1878.     if (screens[scrn].clientflags & PASTE_IN_PROGRESS)    /* BYU 2.4.7 */
  1879.         SysBeep(4);                                        /* BYU 2.4.7 */
  1880.     else {                                                /* BYU 2.4.7 */
  1881.         screens[scrn].clientflags |= PASTE_IN_PROGRESS;    /* BYU 2.4.7 */
  1882.         screens[scrn].incount = 0;                        /* BYU 2.4.7 */
  1883.         screens[scrn].outcount = 0;                        /* BYU 2.4.7 */
  1884.         pasteText(scrn);    /* BYU 2.4.7 - routine to paste to net, w/echo if neccessary */
  1885.     }
  1886. }
  1887.  
  1888. void Macros
  1889.   (
  1890.     void
  1891.   )
  1892. {
  1893.     DialogPtr dtemp;
  1894.     short dItem;
  1895.     int i;
  1896.     Rect dBox;
  1897.     Str255 temp;
  1898.     Handle MacString[10];
  1899.  
  1900.     SetCursor(normcurs);
  1901.  
  1902.     dtemp=GetNewDialog( MacroDLOG,(Ptr) 0L,(WindowPtr) -1L);    /* Bring on the box */
  1903.     UItemAssign( dtemp, 23 , (int (*)()) OutlineItem);
  1904.  
  1905.     for (i=0; i<10; i++) {
  1906.         getmacro( i, &temp);
  1907.  
  1908.         GetDItem( dtemp, i+13, &dItem, &MacString[i], &dBox);
  1909.         setitext( MacString[i], &temp );
  1910.         }
  1911.  
  1912.     dItem=0;                                /* initially no hits */
  1913.     while((dItem>2) || (dItem==0)) {        /* While we are in the loop */
  1914.         ModalDialog((ModalFilterProcPtr) modalProc,&dItem);    /* and do our duty to the box */
  1915.         if (dItem >2 && dItem <13) {
  1916.             i=dItem-3;
  1917.             getmacro( i, &temp);
  1918.  
  1919.             GetDItem( dtemp, i+13, &dItem, &MacString[i], &dBox);
  1920.             setitext( MacString[i], &temp );                /* Revert the mother */
  1921.             SelIText( dtemp, i+13, 0, 32767);                /* And select it... */
  1922.             }
  1923.         }
  1924.         
  1925.     updateCursor(1);
  1926.     
  1927.     if (dItem==DLOGCancel) {
  1928.             DisposDialog( dtemp);
  1929.             return;
  1930.             }
  1931.  
  1932.     for (i=0; i<10; i++) {
  1933.         getitext( MacString[i], &temp);
  1934.         setmacro(i, &temp);
  1935.         }
  1936.  
  1937.     DisposDialog( dtemp);
  1938. }
  1939.  
  1940. void displayStatus
  1941.   (
  1942.     int n,
  1943.     int active
  1944.   )
  1945. {
  1946.     DialogPtr dtemp;
  1947.     short item;
  1948.  
  1949.     SetCursor(normcurs);
  1950.  
  1951. #ifndef MPW
  1952.     if (screens[n].corpse) {
  1953.         paramtext( screens[n].machine,"\Pis awaiting dismissal",0L,0L);
  1954.         }
  1955.     else {
  1956.         if (active <0) {
  1957.                 paramtext( screens[n].machine,"\Pbeing looked up",0L,0L);
  1958.             }
  1959.         else {
  1960.             paramtext( screens[n].name,"\Pbeing opened", 0L, 0L);
  1961.             }
  1962.         }
  1963. #else
  1964.     if (screens[n].corpse) {
  1965.         paramtext( screens[n].machine,"is awaiting dismissal",0L,0L);
  1966.         }
  1967.     else {
  1968.         if (active <0) {
  1969.                 paramtext( screens[n].machine,"being looked up",0L,0L);
  1970.             }
  1971.         else {
  1972.             paramtext( screens[n].name,"being opened", 0L, 0L);
  1973.             }
  1974.         }
  1975. #endif
  1976.  
  1977.     dtemp=GetNewDialog( StatusDLOG,(Ptr) 0L,(WindowPtr) -1L);    /* Bring on the box */
  1978.     UItemAssign( dtemp, 3, (int (*)()) OutlineItem);
  1979.  
  1980.     item =DLOGCancel+1;
  1981.     while (item> DLOGCancel)
  1982.         ModalDialog((ModalFilterProcPtr) modalProc, &item);
  1983.  
  1984.     updateCursor(1);
  1985.     
  1986.     if (item ==DLOGCancel) {
  1987.         netclose(screens[n].port);
  1988.         destroyport( n);
  1989.         }    
  1990.  
  1991.     DisposDialog( dtemp);
  1992. }
  1993.  
  1994. /*
  1995.  *    changeport - handle the menu updates for changing from one port to another
  1996.  */
  1997. void changeport
  1998.   (
  1999.     int oldprt,
  2000.     int newprt
  2001.   )
  2002. {
  2003.  
  2004.     sprintf(tempspot,"oldscrn: %d, newscrn: %d",oldprt,newprt); putln(tempspot);
  2005.     
  2006.     if (screens[oldprt].active==0) 
  2007.         CheckItem(myMenus[Conn], oldprt+3,FALSE);        /* Adjust Conn menu */
  2008.     CheckItem(myMenus[Conn], newprt+3,TRUE);
  2009.  
  2010.     CheckItem(myMenus[Emul], EMbs,FALSE);                        /* Adjust BS */
  2011.     CheckItem(myMenus[Emul], EMdel,FALSE);
  2012.     CheckItem(myMenus[Emul], EMbs+screens[newprt].bsdel,TRUE);    /* and DEL */
  2013.  
  2014.     if (screens[newprt].ESclear)                /* BYU 2.4.8 */
  2015.         CheckItem(myMenus[Emul],EMclear,TRUE);    /* BYU 2.4.8 */
  2016.     else                                         /* BYU 2.4.8 */
  2017.         CheckItem(myMenus[Emul],EMclear,FALSE);    /* BYU 2.4.8 */
  2018.  
  2019.     if (screens[newprt].ESscroll)
  2020.         CheckItem(myMenus[Emul],EMscroll,TRUE);
  2021.     else 
  2022.         CheckItem(myMenus[Emul],EMscroll,FALSE);
  2023.  
  2024.     if (screens[newprt].echo)                     /* LOCAL ECHO */
  2025.         CheckItem(myMenus[Emul],EMecho,TRUE);
  2026.     else                                         /* REMOTE ECHO */
  2027.         CheckItem(myMenus[Emul],EMecho,FALSE);
  2028.         
  2029.     if (screens[newprt].wrap)                     /* wrap on */
  2030.         CheckItem(myMenus[Emul],EMwrap,TRUE);
  2031.     else                                         /* wrap off */
  2032.         CheckItem(myMenus[Emul],EMwrap,FALSE);
  2033.  
  2034.     if (VSiscapturing(screens[newprt].vs))                /* BYU 2.4.18 */
  2035.         CheckItem(myMenus[Emul], EMcapture,TRUE);        /* BYU 2.4.18 */
  2036.     else                                                /* BYU 2.4.18 */
  2037.         CheckItem(myMenus[Emul], EMcapture,FALSE);        /* BYU 2.4.18 */
  2038.  
  2039.     scrn=newprt;
  2040.  
  2041.     SLIP_menus();                            /* BYU 2.4.15 */
  2042.  
  2043.     CheckFonts();
  2044. }
  2045.  
  2046. /*
  2047.  * showNetNumbers    - Show the current network numbers.
  2048.  */
  2049. #ifndef MPW
  2050. #define STR_BASE 1
  2051. #else
  2052. #define STR_BASE 0
  2053. #endif
  2054.  
  2055. void showNetNumbers
  2056.   (
  2057.     void
  2058.   )
  2059. {
  2060.     char tmpout[30],        /* IP Number */
  2061.         tmpout2[75];        /* Aux. Information */
  2062.     DialogPtr dtemp;        /* dialog box pointer */
  2063.     int i,                    /* Looping Var */
  2064.         tmp[4];                /* Integer copy of IP Number */
  2065.     
  2066.     for(i=0; i<4; i++)
  2067.             tmp[i]=(int)myipnum[i];        /* Get integer numbers */
  2068.  
  2069.     if (dynamic) {
  2070.         if (EtherNet)
  2071.             sprintf(&tmpout[STR_BASE],"%d.%d.%d.%d [RARP]",tmp[0],tmp[1],tmp[2],tmp[3]);
  2072.         else
  2073.             sprintf(&tmpout[STR_BASE],"%d.%d.%d.%d [KIP]",tmp[0],tmp[1],tmp[2],tmp[3]);
  2074.         }
  2075.     else
  2076.         sprintf(&tmpout[STR_BASE],"%d.%d.%d.%d",tmp[0],tmp[1],tmp[2],tmp[3]);
  2077.                                         /* create Human-readable numbers */
  2078.  
  2079.     if (EtherNet==-99)
  2080.         sprintf( &tmpout2[STR_BASE], "Driver MacTCP");
  2081.     else
  2082.     if (EtherNet) 
  2083.         sprintf( &tmpout2[STR_BASE], "EtherNet %x:%x:%x:%x:%x:%x\nSlot: %d\nSubnet Mask:%lx",
  2084.             (int)nnmyaddr[0],  (int)nnmyaddr[1],  (int)nnmyaddr[2], 
  2085.             (int)nnmyaddr[3],  (int)nnmyaddr[4],  (int)nnmyaddr[5],
  2086.             EtherNet,mynetmask); 
  2087.     else 
  2088.         sprintf(&tmpout2[STR_BASE],"Appletalk Net: %d\nAppletalk Node: %d\nSubnet Mask:%lx",
  2089.                             (int)nnmyaddr[0]*0x100+(int)nnmyaddr[1],
  2090.                             (int)nnmyaddr[2], mynetmask);
  2091.  
  2092.     paramtext(0L,tmpout,0L,tmpout2);                /* Put Parms in Dlog */
  2093.     
  2094.     dtemp=GetNewDialog(259,(Ptr) 0L,(WindowPtr) -1L);        /* Get Dialog */
  2095.     DrawDialog(dtemp);                                /* Display Dialog */
  2096.  
  2097.     Wait4Mouse();                                    /* Wait for a click */
  2098.  
  2099.     DisposDialog(dtemp);                            /* kill it, kill it */
  2100. }
  2101.  
  2102. int PromptBadDynamic
  2103.   (
  2104.     void
  2105.   )
  2106. {
  2107.     DialogPtr dtemp;
  2108.     short item;
  2109.  
  2110. #ifndef MPW
  2111.     paramtext(0L,"\Pobtain dynamic",0L,0L);
  2112.     if (EtherNet) {
  2113.         paramtext( "\PRARP",0L,0L,0L);
  2114.         }
  2115.     else {
  2116.         paramtext( "\PKIP",0L,0L,0L);
  2117.         if (!dynamic) 
  2118.             paramtext(0L,"\Pregister static",0L,0L);
  2119.         }
  2120. #else
  2121.     paramtext(0L,"obtain dynamic",0L,0L);
  2122.     if (EtherNet) {
  2123.         paramtext( "RARP",0L,0L,0L);
  2124.         }
  2125.     else {
  2126.         paramtext( "KIP",0L,0L,0L);
  2127.         if (!dynamic) 
  2128.             paramtext(0L,"register static",0L,0L);
  2129.         }
  2130. #endif MPW
  2131.  
  2132.     dtemp=GetNewDialog( BadDynDLOG,(Ptr) 0L,(WindowPtr) -1L);    /* Bring on the box */
  2133.     UItemAssign( dtemp, 3, (int (*)()) OutlineItem);
  2134.  
  2135.     item =DLOGCancel+1;
  2136.     while (item> DLOGCancel)
  2137.         if (item ==5) {
  2138.             DisposDialog(dtemp);
  2139.             return(-1);
  2140.             }
  2141.         else ModalDialog((ModalFilterProcPtr) modalProc, &item);
  2142.  
  2143.     DisposDialog( dtemp);
  2144.  
  2145.     if (item ==DLOGCancel) {
  2146.         return(0);
  2147.         }    
  2148.  
  2149.     return(1);
  2150. }
  2151.  
  2152. void reconfigNetwork
  2153.   (
  2154.     int warning
  2155.   )
  2156. {
  2157.     int again=1;
  2158.     int error=1;
  2159.  
  2160.     if (warning)
  2161.         again = PromptBadDynamic();
  2162.  
  2163.     if (again<0) {                        /* REMOVE THIS SOON! */
  2164.         error=0;
  2165.         again=0;
  2166.         }
  2167.     while (again) {
  2168.         again=0; error=0;
  2169.         if ( PromptIP( dynamic)) {
  2170.             if (!EtherNet) {                    /* BYU 2.4.12 - was KIP */
  2171.                 DynamIP(myipnum);                /* KIP Dynamic IP Numbers */
  2172.                 error = RegIP(myipnum);
  2173.                 }
  2174.             else {
  2175.                 netsetip("RARP");                /* RARP Dynamic IP Numbers -ET */
  2176.                 error = netgetrarp();
  2177.                 netgetip(myipnum);
  2178.                 }
  2179.     
  2180.             if (!(myipnum[0] & 0x80))
  2181.                     defmask=0xff000000;                        /* Class A */
  2182.                 else if ( (myipnum[0] & 0xC0 )==0x80)
  2183.                     defmask=0xffff0000;                        /* Class B */
  2184.                 else if ( (myipnum[0] & 0xC0 )==0xC0)
  2185.                     defmask=0xffffff00;                        /* Class C */
  2186.             if (!cmask) mynetmask=defmask;
  2187.             dynamic=1;
  2188.             }
  2189.         else {
  2190.             dynamic =0;
  2191.             error = RegIP(myipnum);
  2192.             }
  2193.         if (error)
  2194.             again=PromptBadDynamic();
  2195.         }
  2196.  
  2197.     if (error)
  2198.         quit();
  2199.     else {
  2200.         setnetconfigs( myipnum,  &mynetmask);    /* Assign the new mask and IP numbers */
  2201.         netarpme(myipnum);                        /* Anyone Else using my IP Number? */
  2202.     
  2203.         Ssetgates();            /* finishes IP inits */
  2204.         }
  2205. }
  2206.  
  2207. void LinesPlease
  2208.   (
  2209.     int scrn
  2210.   )
  2211. {
  2212.     DialogPtr dtemp;
  2213.     Rect dBox;
  2214.     short dItem;
  2215.     Handle lines;
  2216.     char strlines[50];
  2217.     int    numlines,notgood;
  2218.  
  2219.     
  2220.     dtemp=GetNewDialog( LinesDLOG,(Ptr) 0L,(WindowPtr) -1L); /* Bring on the box */
  2221.     UItemAssign( dtemp, 3, (int (*)()) OutlineItem);        /* Default is #3 [OK] */
  2222.     
  2223.     SetCursor(normcurs);
  2224.  
  2225.     notgood = 1;
  2226.     sprintf( strlines, "%d", VSgetlines( screens[scrn].vs) );
  2227.     GetDItem( dtemp, LinesNumber, &dItem, &lines, &dBox);    /* Install the default host */
  2228.  
  2229.     while (notgood) {
  2230.         notgood = 0;                                /* Default to good */
  2231.         setitext( lines , strlines);
  2232.         SelIText( dtemp, LinesNumber, 0, 32767);    /* And select it... */
  2233.     
  2234.         dItem=0;                                /* initially no hits */
  2235.         while((dItem>3) || (dItem==0))            /* While we are in the loop */
  2236.             ModalDialog((ModalFilterProcPtr) modalProc,&dItem); /* and do our duty to the box */
  2237.     
  2238.         if (dItem==DLOGCancel) {
  2239.             DisposDialog( dtemp);
  2240.             return;
  2241.             }
  2242.         
  2243.         getitext( lines, strlines);            /* Get the string */
  2244.         sscanf( strlines, "%d", &numlines);    /* Get the number */
  2245.         
  2246.         if (numlines <10) {
  2247.             numlines = 10;
  2248.             SysBeep(5);
  2249.             notgood=1;
  2250.         } else if (numlines > 200) {
  2251.             numlines = 200;
  2252.             SysBeep(5);
  2253.             notgood=1;
  2254.             }
  2255.         }
  2256.     DisposDialog( dtemp);
  2257.     
  2258.     VSsetlines( screens[scrn].vs, numlines);
  2259.     RSsize( screens[scrn].wind, NULL, 0);
  2260.  
  2261.  
  2262.     if (screens[scrn].naws)                 /* NCSA 2.5: send size of window to server */
  2263.         {                                    /* NCSA 2.5 */
  2264.         char parsedat[20];                    /* NCSA 2.5 */        
  2265.         netpush (screens[scrn].port);        /* NCSA 2.5 */
  2266.                                             /* NCSA 2.5 */
  2267. /* NCSA 2.5: syntax for command is:  IAC SB NAWS widthHI widthLO heightHI heightLO IAC SE */    
  2268.                                             /* NCSA 2.5 */
  2269.         sprintf(parsedat,"%c%c%c%c%c%c%c%c%c",255,250,31,(char)0    /* NCSA 2.5 */
  2270.             ,(char)screens[scrn].width,(char)0,numlines,255,240); /* NCSA 2.5 */
  2271.         netwrite(screens[scrn].port,parsedat,9);                /* NCSA 2.5: send data */        
  2272.         }                                    /* NCSA 2.5 */
  2273.                     
  2274.     updateCursor(1);
  2275. }
  2276.  
  2277. /*******************************************************************/
  2278. /*  setupkeys
  2279. *   Prompt the user for which keys to use for kill, stop and start.
  2280. */
  2281. #define killbox 5
  2282. #define stopbox 6
  2283. #define startbox 7
  2284.  
  2285. void setupkeys
  2286.   (
  2287.     void
  2288.   )
  2289. {
  2290.     DialogPtr dtemp;
  2291.     Rect dBox;
  2292.     short dItem,kItem,sItem,eItem;
  2293.     Handle kbox,sbox,ebox;
  2294.     
  2295.     dtemp=GetNewDialog( SetupDLOG,(Ptr) 0L,(WindowPtr) -1L);    /* Bring on the box */
  2296.     UItemAssign( dtemp, 3, (int (*)()) OutlineItem);            /* Default is #3 [OK] */
  2297.  
  2298.     SetCursor(normcurs);
  2299.     
  2300.     GetDItem( dtemp, killbox, &kItem, &kbox, &dBox);    
  2301.     GetDItem( dtemp, stopbox, &eItem, &ebox, &dBox);    
  2302.     GetDItem( dtemp, startbox, &sItem, &sbox, &dBox);    
  2303.  
  2304.     *tempspot = 0;
  2305.     if (screens[scrn].TELstop > 0) {
  2306.         sprintf(tempspot,"^%c",screens[scrn].TELstop^64);
  2307.         setitext( ebox , tempspot);
  2308.         SelIText( dtemp, stopbox, 0, 32767);
  2309.         }
  2310.     if (screens[scrn].TELgo > 0) {
  2311.         sprintf(tempspot,"^%c",screens[scrn].TELgo^64);
  2312.         setitext( sbox , tempspot);
  2313.         SelIText( dtemp, startbox, 0, 32767);
  2314.         }
  2315.     if (screens[scrn].TELip > 0) {
  2316.         sprintf(tempspot,"^%c",screens[scrn].TELip^64);
  2317.         setitext( kbox , tempspot);
  2318.         SelIText( dtemp, killbox, 0, 32767);
  2319.         }
  2320.     
  2321.         dItem=0;                                /* initially no hits */
  2322.         while((dItem>3) || (dItem==0)) {        /* While we are in the loop */
  2323.             ModalDialog((ModalFilterProcPtr) modalProc,&dItem); /* and do our duty to the box */
  2324.  
  2325. /*
  2326. *  intermediate check.  If they hit a key, put its number in the box.
  2327. */
  2328.             getitext( kbox, tempspot);            /* Get the string */
  2329.             if (*tempspot < 32 && *tempspot > 0) {
  2330.                 sprintf(tempspot,"^%c",*tempspot^64);
  2331.                 setitext( kbox , tempspot);
  2332.                 SelIText( dtemp, killbox, 0, 32767 );
  2333.                 }
  2334.             getitext( ebox, tempspot);            /* Get the string */
  2335.             if (*tempspot < 32 && *tempspot > 0) {
  2336.                 sprintf(tempspot,"^%c",*tempspot^64);
  2337.                 setitext( ebox , tempspot);
  2338.                 SelIText( dtemp, stopbox, 0, 32767);
  2339.                 }
  2340.             getitext( sbox, tempspot);            /* Get the string */
  2341.             if (*tempspot < 32 && *tempspot > 0) {
  2342.                 sprintf(tempspot,"^%c",*tempspot^64);
  2343.                 setitext( sbox , tempspot);
  2344.                 SelIText( dtemp, startbox, 0, 32767);
  2345.                 }
  2346.                 
  2347.             }
  2348.                 
  2349.     
  2350.         if (dItem==DLOGCancel) {
  2351.             DisposDialog( dtemp);
  2352.             return;
  2353.             }
  2354.             
  2355.         getitext( kbox, tempspot);            /* Get the string */
  2356.         if (*tempspot != '^') 
  2357.             screens[scrn].TELip = -1;
  2358.         else
  2359.             screens[scrn].TELip = toupper(*(tempspot+1)) ^ 64;
  2360.             
  2361.         getitext( ebox, tempspot);            /* Get the string */
  2362.         if (*tempspot != '^') 
  2363.             screens[scrn].TELstop = -1;
  2364.         else
  2365.             screens[scrn].TELstop = toupper(*(tempspot+1)) ^ 64;
  2366.  
  2367.         getitext( sbox, tempspot);            /* Get the string */
  2368.         if (*tempspot != '^') 
  2369.             screens[scrn].TELgo = -1;
  2370.         else
  2371.             screens[scrn].TELgo = toupper(*(tempspot+1)) ^ 64;
  2372.             
  2373.             
  2374.     DisposDialog( dtemp);
  2375.  
  2376.     updateCursor(1);
  2377. }
  2378.  
  2379. /*
  2380.  *    . - preform a command denoted by the arguments.
  2381.  *        mResult - the result of the menu event
  2382.  *        modifiers- modifiers from the menu event
  2383.  */
  2384.  
  2385. void docommand
  2386.   (
  2387.     long mResult,
  2388.     short modifiers
  2389.   )
  2390. {
  2391.     register int i;
  2392.     int theItem, theMenu;
  2393.  
  2394.     theMenu = mResult >> 16;
  2395.     theItem = mResult & 0xffff;
  2396.     switch(theMenu) {
  2397.     case appleMenu:
  2398.         if (theItem==1)                /* About Dialog */
  2399.             applAbout();
  2400.         else
  2401.           {
  2402.             Str255
  2403.                 name;
  2404.             GetItem(myMenus[0], theItem, name);        /* Desk accessory */
  2405.             OpenDeskAcc(name);
  2406.           }
  2407.         break;
  2408.  
  2409.     case fileMenu:
  2410.         switch(theItem) {            
  2411.             
  2412.         case FLopen:
  2413.             setupport(NOFTP);                            /* Open a connection */                
  2414.             break;
  2415.  
  2416.         case FLclose:
  2417.                 if ( numwindows<1 ) break;                /* Close a connection */
  2418.                 if ( screens[scrn].corpse) {
  2419.                     netclose( screens[scrn].port);
  2420.                     destroyport( scrn);
  2421.                     }
  2422.                 else {
  2423.                     if ( !ReallyClose( scrn) ) break;
  2424.                     netclose(screens[scrn].port);
  2425.                     removeport( scrn);
  2426.                     }
  2427.                 if (numwindows <1) 
  2428.                     {
  2429.                     DisableItem( myMenus[Conn],0);
  2430.                     DisableItem(myMenus[Conn],COnext);
  2431.                     DrawMenuBar();
  2432.                     }
  2433.             break;
  2434.  
  2435.         case FLload:                                /* Load a set */
  2436.             LoadCONF();
  2437.             break;
  2438.         case FLsave:                                /* Save a set */
  2439.             if (numwindows<1) break;
  2440.             SaveCONF();
  2441.             break;
  2442.         case FLftp:
  2443.             ftpavail=!ftpavail;                        /* Toggle FTP on/off  */
  2444.             if (ftpavail) {
  2445.                 CheckItem(myMenus[Fil], FLftp,TRUE);
  2446.                 Sftpmode(1);
  2447.                 }
  2448.             else {
  2449.                 CheckItem(myMenus[Fil], FLftp,FALSE);
  2450.                 Sftpmode(0);
  2451.                 }
  2452.             break;
  2453.  
  2454.         case FLbin:                                    /* Toggle MacBinary on/off */
  2455.             MacBinary = !MacBinary;
  2456.             if (MacBinary) {
  2457.                 CheckItem(myMenus[Fil], FLbin,TRUE);
  2458.                 }
  2459.             else {
  2460.                 CheckItem(myMenus[Fil], FLbin,FALSE);
  2461.                 }
  2462.             break;
  2463.  
  2464.         case FLlog:                                        /* Toggle FTP window on/off*/
  2465.             ftplogon=!ftplogon;
  2466.             if(ftplogon) {
  2467.                 CheckItem(myMenus[Fil],FLlog,TRUE);
  2468.                 RSshow(ftplog.vs);
  2469.                 SelectWindow(ftplog.wind);
  2470.                 }
  2471.             else {
  2472.                 CheckItem(myMenus[Fil],FLlog,FALSE);
  2473.                 RShide(ftplog.vs);
  2474.                 }
  2475.             break;
  2476.  
  2477.         case FLdir:                                        /* Set the working dir. */
  2478.             wdset();
  2479.             break;
  2480.  
  2481.         case FLprint:                                /* Print Selection (or gr) */
  2482.             if (prRecHdl==0L) {                        /* Make sure print is inited */
  2483.                 PrOpen();
  2484.                 prRecHdl=(THPrint)NewHandle((long)sizeof(TPrint));
  2485.                 PrintDefault(prRecHdl);
  2486.                 }
  2487.             i=RGgetdnum(FrontWindow());
  2488.             if (i>-1)         
  2489.                 printGraph( i);                        /* Print Graphics */
  2490.             else 
  2491.                 if ( (i=RSfindvwind(FrontWindow())) >-1 ) {
  2492.                     Str255 Title;
  2493.  
  2494.                     getwtitle( FrontWindow(), &Title);
  2495.                     printText(i, (Str255 *) &Title,scrn);    /* Print Text selection */
  2496.                     }
  2497.             break;
  2498.  
  2499.         case FLpset:                                    /* Set up for printer */
  2500.             if (prRecHdl==0L) {                        /* make sure print is inited */
  2501.                 PrOpen();
  2502.                 prRecHdl=(THPrint)NewHandle((long)sizeof(TPrint));
  2503.                 PrintDefault(prRecHdl);
  2504.                 }
  2505.             PrStlDialog(prRecHdl);                    /* Present the style dlog*/
  2506.             break;
  2507.  
  2508.         case FLquit:
  2509.             if (numwindows>0)
  2510.               {
  2511.                 if (ReallyQuit())
  2512.                   {
  2513.                     serial_shut();                    /* BYU serial - close serial port */
  2514.                     for (i = numwindows - 1; i >= 0; i--)
  2515.                       {
  2516.                         netclose(screens[i].port);
  2517.                         destroyport(i);
  2518.                       } /* for */
  2519.                   }
  2520.                 else
  2521.                     break;
  2522.               } /* if */
  2523.             quit();                                    /* Guess what this does */
  2524.             break;
  2525.  
  2526.         }
  2527.         break;
  2528.  
  2529.     case editMenu:
  2530.         if (!SystemEdit(theItem-1)) {                /* Is this mine? */
  2531.             switch(theItem) {
  2532.             case EDcopy:                            /* Copy */
  2533.                 i = MacRGfindwind(FrontWindow());    /* is ICR window? */
  2534.                 if (i >= 0)
  2535.                     MacRGcopy(FrontWindow());        /* copy the ICR window */
  2536.                 else {
  2537.                     i=RGgetdnum(FrontWindow());
  2538.                     if (i>-1)                        /* Copy Graphics */
  2539.                         copyGraph( i);
  2540.                     else                            /* Copy Text */
  2541.                         if ( (i=RSfindvwind(FrontWindow())) >-1)
  2542.                             copyText( i);
  2543.                 }
  2544.                 break;
  2545.  
  2546.             case EDcopyt:                            /* Copy Table */
  2547.                 /* 
  2548.                 *  tech note #180 trick to get MultiFinder to pay attention 
  2549.                 */
  2550.                 if (!SystemEdit(EDcopy-1)) {        /* tell it we did a copy */
  2551.                     i=RGgetdnum(FrontWindow());
  2552.                     if (i>-1)            /* Copy Graphics */
  2553.                         copyGraph( i);
  2554.                     else                /* Copy Text */
  2555.                         if ( (i=RSfindvwind(FrontWindow())) >-1)
  2556.                             copyTable( i);
  2557.                 }
  2558.                 break;
  2559.  
  2560.             case EDpaste:                            /* Paste */
  2561.                 if (numwindows<1)
  2562.                         break;
  2563.                     else paste();            /* Paste if there is a wind to do to*/
  2564.                 break;
  2565.             case EDmacros:                            /* Set them Macros */
  2566.                 Macros();
  2567.                 break;
  2568.             case EDprefs:                            /* You know what I like! */
  2569.                 PromptPrefs();
  2570.                 break;
  2571.             default:
  2572.                 break;
  2573.             }
  2574.         }
  2575.         break;
  2576.  
  2577.     case connMenu:
  2578.         if (theItem==1)
  2579.             {
  2580.             if (numwindows >1) 
  2581.                 {
  2582.                 SendBehind( FrontWindow(), 0L);
  2583.                 if (FrontWindow() == console.wind || FrontWindow() == ftplog.wind)
  2584.                     SendBehind( FrontWindow(), 0L);
  2585.                 }
  2586.             break;
  2587.             }
  2588.             
  2589.         else
  2590.             {
  2591.             if ((theItem-2)>(numwindows+1)) break;  /* rotten danish */
  2592.             if (screens[ --theItem-2].active!=0) 
  2593.                 {
  2594.                 displayStatus(theItem-2, screens[theItem-1].active);    /* Tell them about it..... */
  2595.                 break;
  2596.                 }
  2597.             else 
  2598.                 {
  2599.                 HiliteWindow(screens[scrn].wind, FALSE);
  2600.                 changeport(scrn,(theItem-2));
  2601.                 if (!(modifiers &  optionKey)) SelectWindow(screens[scrn].wind);
  2602.                     else HiliteWindow(screens[scrn].wind, TRUE);
  2603.                 }
  2604.             }
  2605.         break;
  2606.  
  2607.     case netMenu:
  2608.         switch(theItem) {
  2609.         case NEftp:                                        /* Send FTP command */
  2610.         case NEip:                                        /* Send IP Number */
  2611.             if (numwindows<1) break;
  2612.             {    char tmpout[30];                        /* Basically the same except for */
  2613.                 int tmp[4];                                /* The ftp -n phrase in NEftp */
  2614.  
  2615.                 if (screens[scrn].echo && (screens[scrn].kblen>0)) {
  2616.                     netwrite( screens[scrn].port, screens[scrn].kbbuf,
  2617.                                 screens[scrn].kblen);/* if not empty send buffer */
  2618.                     screens[scrn].kblen=0;
  2619.                     }
  2620.                 if (screens[scrn].connectionType == 1)                    /* BYU 2.4.15 */
  2621.                     for(i=0; i<4; i++) tmp[i]=(int)SLIP_ip_number[i];    /* BYU 2.4.15 */
  2622.                 else                                                    /* BYU 2.4.15 */
  2623.                     for(i=0; i<4; i++) tmp[i]=(int)myipnum[i];            /* BYU 2.4.15 */
  2624.                 if (theItem == NEftp) {
  2625.                     if ((modifiers & shiftKey) != 0)                                                /* BYU mod */
  2626.                         sprintf(tmpout,"ftp %d.%d.%d.%d\015\012",tmp[0],tmp[1],tmp[2],tmp[3]);        /* BYU mod */
  2627.                     else                                                                            /* BYU mod */
  2628.                         sprintf(tmpout,"ftp -n %d.%d.%d.%d\015\012",tmp[0],tmp[1],tmp[2],tmp[3]);    /* BYU mod */
  2629.                     }                                                                                /* BYU mod */
  2630.                 else
  2631.                     sprintf(tmpout,"%d.%d.%d.%d",tmp[0],tmp[1],tmp[2],tmp[3]);
  2632.                 netwrite(screens[scrn].port,tmpout,strlen(tmpout));
  2633.                 if (screens[scrn].echo)
  2634.                     VSwrite(screens[scrn].vs,tmpout, strlen(tmpout));
  2635.             }
  2636.             break;
  2637.  
  2638.         case NEayt:                                /* Send "Are You There?"*/
  2639.             if (numwindows<1) break;
  2640.             netpush(screens[scrn].port);
  2641.             netwrite(screens[scrn].port, "\377\366",2);
  2642.             break;
  2643.  
  2644.         case NEao:                                /* Send "Abort Output"*/
  2645.             if (numwindows<1) break;
  2646.             netpush(screens[scrn].port);
  2647.             netwrite(screens[scrn].port, "\377\365",2);
  2648.             screens[ scrn].timing = 1;                        /* set emulate to TMwait */
  2649.             netwrite(screens[scrn].port, "\377\375\006",3);        /* send TM */
  2650.             break;
  2651.  
  2652.         case NEinter:                                /* Send "Interrupt Process"*/
  2653.             if (numwindows<1) break;
  2654.             netpush(screens[scrn].port);
  2655.             netwrite(screens[scrn].port, "\377\364",2);
  2656.             screens[ scrn].timing = 1;                        /* set emulate to TMwait */
  2657.             netwrite(screens[scrn].port, "\377\375\006",3);        /* send TM */
  2658.             break;
  2659.  
  2660.         case NEec:                                /* Send "Erase Character"*/
  2661.             if (numwindows<1) break;
  2662.             netpush(screens[scrn].port);
  2663.             netwrite(screens[scrn].port, "\377\367",2);
  2664.             break;
  2665.  
  2666.         case NEel:                                /* Send "Erase Line"*/
  2667.             if (numwindows<1) break;
  2668.             netpush(screens[scrn].port);
  2669.             netwrite(screens[scrn].port, "\377\370",2);
  2670.             break;
  2671.             
  2672.         case NEscroll:                            /* Suspend Network */
  2673.             ScrlLock=!ScrlLock;
  2674.             if (ScrlLock) 
  2675.                 CheckItem(myMenus[Net], NEscroll,TRUE);
  2676.             else 
  2677.                 CheckItem(myMenus[Net], NEscroll,FALSE);
  2678.             break;
  2679.  
  2680.         case NEnet:                                /* Show Network Numbers */
  2681.             showNetNumbers();
  2682.             break;
  2683.  
  2684.         case NEconfig:
  2685.             if (userlevel != 0) break;
  2686.             if (EtherNet == -99)                /* drivers are alive version */
  2687.                 driverconf();                    /* just configure default host */
  2688.             else {
  2689.                 if (numwindows > 0) break;
  2690.                 reconfigNetwork(0);
  2691.                 }
  2692.             break;
  2693.  
  2694.         case NEserial:            /* BYU serial */
  2695.             Setmodem();            /* BYU serial */
  2696.             break;                /* BYU serial */
  2697.  
  2698.         case NEalias:            /* NCSA */
  2699.             DoAlias();            /* NCSA */
  2700.             break;                /* NCSA */
  2701.  
  2702.         default:
  2703.             break;
  2704.         }
  2705.         break;
  2706.  
  2707.     case termMenu:
  2708.         switch(theItem) {
  2709.  
  2710.         case EMbs:                                /* Backspace for backspace  */
  2711.             if (numwindows<1) break;
  2712.             CheckItem(myMenus[3], EMbs+screens[scrn].bsdel,FALSE);
  2713.             screens[scrn].bsdel=0;
  2714.             CheckItem(myMenus[3], EMbs+screens[scrn].bsdel,TRUE);
  2715.             break;
  2716.         
  2717.         case EMdel:                                /* Delete for backspace */
  2718.             if (numwindows<1) break;
  2719.             CheckItem(myMenus[3], EMbs+screens[scrn].bsdel,FALSE);
  2720.             screens[scrn].bsdel=1;
  2721.             CheckItem(myMenus[3], EMbs+screens[scrn].bsdel,TRUE);
  2722.             break;
  2723.  
  2724.         case EMecho:                                /* Toggle Local Echo (if poss.) */
  2725.             if (numwindows < 1) break;
  2726.             if (screens[scrn].echo && (screens[scrn].kblen>0)) {
  2727.                 netwrite( screens[scrn].port, screens[scrn].kbbuf,
  2728.                             screens[scrn].kblen);    /* if not empty send buffer */
  2729.                 screens[scrn].kblen=0;
  2730.                 }
  2731.             screens[scrn].echo= !screens[scrn].echo;    /* toggle */
  2732.             if (screens[scrn].echo) {                    /* LOCAL ECHO */
  2733.                 netwrite(screens[scrn].port,"\377\376\001",3);
  2734.                 CheckItem(myMenus[3],EMecho,TRUE);
  2735.                 }
  2736.             else {                                        /* REMOTE ECHO */
  2737.                 netwrite(screens[scrn].port,"\377\375\001",3);
  2738.                 CheckItem(myMenus[3],EMecho,FALSE);
  2739.                 }
  2740.             break;
  2741.             
  2742.         case EMwrap:                                /* wrap mode */
  2743.             if (numwindows < 1) break;
  2744.             if (!screens[scrn].wrap) {                /* is off, turn on */
  2745.                 screens[scrn].wrap = 1;
  2746.                 CheckItem( myMenus[3],EMwrap, TRUE);
  2747.                 VSwrite(screens[scrn].vs, "\033[?7h",5);    /* kick emulator */
  2748.                 }
  2749.             else {
  2750.                 screens[scrn].wrap = 0;
  2751.                 CheckItem( myMenus[3],EMwrap, FALSE);
  2752.                 VSwrite(screens[scrn].vs, "\033[?7l",5);
  2753.                 }
  2754.             break;
  2755.  
  2756.         case EMscroll:                                        /* Scrollback on CLS */
  2757.             if (numwindows<1) break;
  2758.             screens[scrn].ESscroll = !screens[scrn].ESscroll;
  2759.             VSscrolcontrol( screens[scrn].vs, -1, screens[scrn].ESscroll);
  2760.             if (screens[scrn].ESscroll)
  2761.                 CheckItem(myMenus[3],EMscroll, TRUE);
  2762.             else
  2763.                 CheckItem(myMenus[3],EMscroll, FALSE);
  2764.             break;
  2765.             
  2766.         case EMpage:                                    /* TEK page command */
  2767.             if (numwindows<1) break;
  2768.             parse( &screens[scrn],  "\033\014",2);
  2769.             break;
  2770.  
  2771.         case EMclear:                                /* BYU 2.4.8 - Clear on TEK page */
  2772.             if (numwindows<1) break;                        /* BYU 2.4.8 */
  2773.             screens[scrn].ESclear = !screens[scrn].ESclear;    /* BYU 2.4.8 */
  2774.             if (screens[scrn].ESclear)                        /* BYU 2.4.8 */
  2775.                 CheckItem(myMenus[3],EMclear, TRUE);        /* BYU 2.4.8 */
  2776.             else                                            /* BYU 2.4.8 */
  2777.                 CheckItem(myMenus[3],EMclear, FALSE);        /* BYU 2.4.8 */
  2778.             break;                                            /* BYU 2.4.8 */
  2779.  
  2780.         case EMlines:                                    /* set the # of lines */
  2781.             if (numwindows<1) break;
  2782.             LinesPlease( scrn);
  2783.             break;
  2784.             
  2785.         case EMreset:                                    /* Reset Screen */
  2786.             if (numwindows<1) break;
  2787.             VSreset(screens[scrn].vs);                    /* Reset it */
  2788.             screens[scrn].timing=0;
  2789.             screens[scrn].wrap = 0;                        /* turns wrap off */
  2790.             CheckItem( myMenus[3],EMwrap, FALSE);
  2791.             break;
  2792.         case EMjump:                                    /* Jump Scroll */
  2793.             if (numwindows<1) break;
  2794.             FlushNetwork(scrn);                            /* Flush it */
  2795.             break;
  2796.             
  2797.         case EMsetup:                            /* need dialog to enter new key values */
  2798.             setupkeys();
  2799.             break;
  2800.  
  2801.         case EMcolor:                                        /* Set color */
  2802.             if (numwindows<1) break;
  2803.             if (HasColor)
  2804.                 RScprompt(screens[scrn].vs, (int (*)()) modalProc);    /* Color it */
  2805.             break;
  2806.  
  2807.         case EMslip:                            /* BYU 2.4.15 - Switch to SLIP */
  2808.             if (numwindows<1)                    /* BYU 2.4.15 */
  2809.                 break;                            /* BYU 2.4.15 */
  2810.             switchtoslip(screens[scrn].port);    /* BYU 2.4.15 */
  2811.             break;                                /* BYU 2.4.15 */
  2812.  
  2813.         case EMserial:                            /* BYU 2.4.15 - Switch to Serial */
  2814.             if (!slip_connection)                /* BYU 2.4.16 */
  2815.                 break;                            /* BYU 2.4.15 */
  2816.             slip_connection = 0;                /* BYU 2.4.15 */
  2817.             serial_scrn = -1;                    /* BYU 2.4.15 */
  2818.             SLIP_menus();                        /* BYU 2.4.16 */
  2819.             break;                                /* BYU 2.4.15 */
  2820.  
  2821.         case EMcapture:                                            /* BYU 2.4.18 - Capture session to file */
  2822.             if (VSiscapturing(screens[scrn].vs)) {                /* BYU 2.4.18 */
  2823.                 CloseCaptureFile(screens[scrn].vs);                /* BYU 2.4.18 */
  2824.             } else {                                            /* BYU 2.4.18 */
  2825.                 if(!VSopencapture(scrn, screens[scrn].vs))        /* BYU 2.4.18 */
  2826.                     CheckItem(myMenus[Emul], EMcapture,TRUE);    /* BYU 2.4.18 */
  2827.             }                                                    /* BYU 2.4.18 */
  2828.  
  2829.             break;                                                /* BYU 2.4.18 */
  2830.  
  2831. #ifdef NOTANYMORE
  2832.         case EMcommand:                                    /* Switch menus */
  2833.             whichMenus=!whichMenus;
  2834.             switchMenus(whichMenus);
  2835.             break;
  2836. #endif NOTANYMORE
  2837.         default:
  2838.             break;
  2839.         }
  2840.         break;
  2841.     case fontMenu:
  2842.         if (numwindows>0) {
  2843.             RSchangefont( screens[scrn].vs, FontNumber[theItem], 0, 1);
  2844.             CheckFonts();
  2845.             }
  2846.         break;
  2847.     case sizeMenu:
  2848.         if (numwindows>0) {
  2849.             RSchangefont( screens[scrn].vs, -1, FontSize[theItem], 1);
  2850.             CheckFonts();
  2851.             }
  2852.         break;
  2853.     default:
  2854.         break;
  2855.     
  2856.     }
  2857.     HiliteMenu(0);
  2858.   } /* docommand */
  2859.  
  2860. /*
  2861.  *    portsOpen()    - Count the number of ports open. Returns 3 different answers
  2862.  *                  0= no ports at all, 1= at least active, -1= ports/none active.
  2863.  */
  2864.  
  2865. int portsOpen()
  2866. {
  2867.     int pnum;
  2868.  
  2869.     pnum=numwindows-1;
  2870.     if (pnum<0)  return(0);
  2871.     while (pnum>=0) 
  2872.         if (!screens[pnum--].active && !screens[pnum+1].corpse) return(1);
  2873.     return(-1);
  2874. }
  2875.  
  2876. /*
  2877.  *    extractmenu - remove a connection from the menu.
  2878.  */
  2879.  
  2880. void extractmenu
  2881.   (
  2882.     int pnum
  2883.   )
  2884. {
  2885.     DelMenuItem(myMenus[Conn],pnum+3);
  2886.  
  2887.     AdjustMenus();
  2888. }
  2889.  
  2890. /*
  2891.  *    addinmenu - add a connection's name to the menu in position pnum. (name is
  2892.  *        an str255 pointed at by temps).
  2893.  */
  2894.  
  2895. void addinmenu
  2896.   (
  2897.     int pnum,
  2898.     Str255 *temps,
  2899.     char mark
  2900.   )
  2901. {
  2902.     
  2903.     insmenuitem(myMenus[Conn], (char *) temps, pnum+2);        /* add string to connections menu */
  2904.  
  2905.     SetItemMark( myMenus[Conn], pnum+3, mark);        /* check this with the appropriate mark */
  2906.     AdjustMenus();
  2907. }
  2908.  
  2909. /*
  2910.  *    opnport(scrn) -    Sets the item mark for <scrn> to opening connection 
  2911.  */
  2912.  
  2913. void opnport
  2914.   (
  2915.     int scrn
  2916.   )
  2917. {
  2918.     unsigned char c=0xa5;
  2919.  
  2920.     SetItemMark( myMenus[Conn],scrn+3, c );
  2921. }
  2922.  
  2923. /*
  2924.  *    liveport(scrn) -    Sets the item mark for <scrn> to opened connection 
  2925.  */
  2926.  
  2927. void liveport
  2928.   (
  2929.     int scrn
  2930.   )
  2931. {
  2932.     unsigned char c=0x00;
  2933.  
  2934.     SetItemMark( myMenus[Conn],scrn+3, c);
  2935.     AdjustMenus();
  2936. }
  2937.  
  2938. /*
  2939.  *    RGtoPICT(i)        - Converts the data in TEK window <i> to PICT format.
  2940.  *                      returns the handle to the picture.
  2941.  */
  2942.  
  2943. PicHandle RGtoPICT(i)
  2944. int i;
  2945. {
  2946.     int j;
  2947.     PicHandle tpic;
  2948.     Rect trect;
  2949.  
  2950.     SetRect(&trect,0,0,384,384);
  2951.     j=VGnewwin(3,VGgetVS(i));            /* NCSA 2.5: get the right VS */
  2952.     RGMPsize( &trect );
  2953.     VGzcpy( i, j);                /* Love dat zm factr */
  2954.     tpic=OpenPicture(&trect);
  2955.     ClipRect(&trect);
  2956.     
  2957.     VGredraw(i,j);
  2958.     ClosePicture();
  2959.     VGclose(j);
  2960.  
  2961.     return(tpic);
  2962. }
  2963.  
  2964. /*
  2965.  *    printsleep()    - Provide the network keep alive while we are in print
  2966.  *                      mode.  Also set the abort flag if necessary.
  2967.  */
  2968. void printsleep()
  2969. {
  2970.     Stask();                        /* act like the postman */
  2971.     if (userabort()) (*prRecHdl)->prJob.fFromUsr=TRUE;
  2972. }
  2973.  
  2974.  
  2975.  
  2976.  
  2977.  
  2978. /*------------------------------------------------------------------*/
  2979. /* Alias code                                                        */
  2980. /* NCSA, April 1992                                                    */
  2981. /*------------------------------------------------------------------*/
  2982.  
  2983.  
  2984.  
  2985. /* Find out which item is selected */
  2986. short GetSelectedAlias(ListHandle hList,int theNum)
  2987. {
  2988.     short i;
  2989.     Point theCell;
  2990.     
  2991.     for (i=0;i < theNum;i++)
  2992.         {
  2993.         SetPt(&theCell,0,i);
  2994.         if (LGetSelect(0,&theCell,hList))
  2995.             return i;
  2996.         } 
  2997.     return 0;
  2998. }
  2999.  
  3000.  
  3001.  
  3002.  
  3003. /* Get the list of aliases from the resource file "NCSA Prefs."
  3004.     If there is no such list yet, then make one from scratch */
  3005. AliasRez **GetAlias()
  3006. {
  3007.     AliasRez **theResource;
  3008.     AliasRez *pAliasrez, **hAliasrez;
  3009.     int terr;
  3010.         
  3011.     theResource = (AliasRez **)GetResource('alia',1000);
  3012.     if (theResource !=0L) 
  3013.         return theResource;        /* send it */
  3014.     
  3015.     else /* Make a new one from scratch */
  3016.         {
  3017.  
  3018.         hAliasrez = (AliasRez **)NewHandle(sizeof(AliasRez));
  3019.         HLock ((Handle)hAliasrez);
  3020.         
  3021.         pAliasrez = *hAliasrez;
  3022.         pAliasrez->number =0;
  3023.         pAliasrez->aliases[0].name[0] = 0;        /* no data for us */
  3024.         pAliasrez->aliases[0].port = 0;
  3025.         pAliasrez->aliases[0].alias[0] = 0;
  3026.         HUnlock((Handle)hAliasrez);
  3027.         
  3028.  
  3029. /* add this to the resource file, and check for some strange errors */
  3030.  
  3031.         addresource((Handle)hAliasrez,'alia',1000,"aliases");    /* NCSA 2.5 */
  3032.         if ((terr=ResError())!=0) {
  3033.             putln("Error in addresource");
  3034.             }
  3035.         else 
  3036.             {
  3037.             ChangedResource((Handle)hAliasrez);
  3038.             UpdateResFile(HomeResFile((Handle) hAliasrez));
  3039.             }
  3040.         return hAliasrez;
  3041.         }
  3042. }        
  3043.     
  3044.  
  3045. /* called when a record needs to be deleted, and all the records
  3046.     after it have to be bumped up a slot... */
  3047. void DeleteAlias (short theNum, AliasRez **hAlias)
  3048. {
  3049.     short i;
  3050.     AliasRez *pResource;
  3051.     
  3052.     pResource = *hAlias;        /* shut up, Tim */
  3053.     
  3054.     pResource->number--;
  3055.     for (i=theNum;i < pResource->number; i++)
  3056.         {
  3057.         strcpy(pResource->aliases[i].name,pResource->aliases[i+1].name);
  3058.         strcpy(pResource->aliases[i].alias, pResource->aliases[i+1].alias);
  3059.         pResource->aliases[i].port = pResource->aliases[i+1].port;
  3060.         }
  3061. }
  3062.  
  3063.  
  3064.  
  3065. /* this is the main controlling routine.  Called from DoCommand each
  3066.     time the user selects the Alias... menu item.  Get the data from the
  3067.     resource file, and allow the user to add and remove items, in a modal
  3068.     dialog setting.  At the end, save all relevant changes back to the
  3069.     resource file, and then relax until next time*/
  3070. void DoAlias
  3071.   (
  3072.     void
  3073.   )
  3074. {
  3075.     DialogPtr dtemp;
  3076.     short dItem;
  3077.     Rect dBox;
  3078.     Handle     hHost,hPort,hAlias,hList;        /* dialog control handles */
  3079.     AliasRez **theResource,*pResource;        /* alias resource data */
  3080.     short oldSize,numRecords;
  3081.     char junk[64];
  3082.     ListHandle theList;                        /* our List */
  3083.     Rect listBounds;
  3084.     Point    cellSize,theCell;
  3085.     GrafPtr savePort;                        /* Dont hammer the port! */
  3086.     short i;
  3087.     
  3088.     theResource = GetAlias();            /* get the resource */
  3089.     dtemp=GetNewDialog( AliasDLOG, (Ptr) 0L, (WindowPtr) -1L);    /* Bring on the box */
  3090.     GetPort (&savePort);
  3091.     SetPort((GrafPtr)dtemp);
  3092.     UItemAssign( dtemp, kAliasOutline , (int (*)()) OutlineItem);
  3093.  
  3094.         
  3095. /* lets get some initial data */
  3096.     GetDItem( dtemp, kAliasHostItem, &dItem, &hHost, &dBox);
  3097.     GetDItem( dtemp, kAliasPortItem, &dItem, &hPort, &dBox);
  3098.     GetDItem( dtemp, kAliasAliasItem, &dItem, &hAlias, &dBox);
  3099.     GetDItem( dtemp, kAliasList, &dItem, &hList, &dBox);
  3100.  
  3101.     SetRect(&listBounds,0,0,1,0);
  3102.     SetPt(&cellSize,150,20);
  3103.     
  3104.     FrameRect(&dBox);
  3105.     InsetRect(&dBox,1,1); 
  3106.     dBox.right -= 16;
  3107.     
  3108.     theList = LNew(&dBox,&listBounds,cellSize,0,(WindowPtr)dtemp,
  3109.         1,0,0,1);        /* make the new list from scratch */
  3110.  
  3111.     HLock((Handle)theResource);
  3112.     pResource = *theResource;
  3113.  
  3114. /* add all of the saved aliases to the list */
  3115.  
  3116.     for (i=0;i< (**theResource).number;i++)
  3117.         {
  3118.         LAddRow(1,0,theList); 
  3119.         SetPt(&theCell,0,0);
  3120.         LSetCell(pResource->aliases[i].alias,strlen(pResource->aliases[i].alias),
  3121.                 theCell,theList);
  3122.         }
  3123.     HUnlock((Handle)theResource);
  3124.     LSetSelect(1,theCell,theList);
  3125.  
  3126.  
  3127.     SelIText( dtemp, kAliasHostItem, 0, 32767);
  3128.     HLock((Handle)theResource);
  3129.     pResource = *theResource;
  3130.  
  3131.  
  3132. /* this is the main dialog routine.  Keep chugging away until the user
  3133.     hits OK, or Cancel.  Make sure the list is updated each time the
  3134.     user hits inside our list rect */
  3135.  
  3136.     dItem=0;                                /* initially no hits */
  3137.     while((dItem>2 ) || (dItem==0)) {                    /* While we are in the loop */
  3138.         ModalDialog((ModalFilterProcPtr) modalProc,&dItem); /* and do our duty to the box */
  3139.  
  3140.         if (dItem == kAliasAdd)
  3141.             {
  3142.             oldSize = GetHandleSize((Handle)theResource);
  3143.             SetHandleSize((Handle)theResource,oldSize + sizeof(AliasRecord));
  3144.             numRecords = pResource->number++;
  3145.             getitext(hHost,pResource->aliases[numRecords].name);        /* NCSA 2.5 */
  3146.             getitext(hAlias,pResource->aliases[numRecords].alias);        /* NCSA 2.5 */
  3147.             getitext(hPort,junk);                                        /* NCSA 2.5 */
  3148.             sscanf(junk,"%d",&pResource->aliases[numRecords].port);
  3149.             theCell.h=0;
  3150.             theCell.v = GetSelectedAlias (theList, numRecords-1);
  3151.             LSetSelect(0,theCell, theList);
  3152.             SetPt(&theCell,0,0);
  3153.             
  3154.             LAddRow(1,0,theList); 
  3155.             LSetCell(pResource->aliases[numRecords].alias,strlen(pResource->aliases[numRecords].alias),
  3156.                 theCell,theList);
  3157.             LSetSelect(1,theCell,theList);
  3158.             }
  3159.  
  3160.         if (dItem == kAliasRemove )
  3161.             {
  3162.             numRecords = pResource->number;
  3163.             theCell.v = GetSelectedAlias (theList, numRecords );            
  3164.             LDelRow(1,theCell.v,theList);
  3165.             DeleteAlias(numRecords - theCell.v -1,theResource);
  3166.             SetPt(&theCell,0,0);
  3167.             LSetSelect(1,theCell, theList);
  3168.             oldSize = GetHandleSize((Handle)theResource);
  3169.             SetHandleSize((Handle)theResource,oldSize - sizeof(AliasRecord));
  3170.             } 
  3171.  
  3172.         if (dItem == kAliasList)
  3173.             {
  3174.             Point theMouse;
  3175.             
  3176.             GetMouse(&theMouse);
  3177.             LClick(theMouse,kListMods,theList);
  3178.             theCell = LLastClick(theList);
  3179.             }
  3180.         }
  3181.  
  3182.  
  3183.     HUnlock((Handle)theResource);    /* Now you can munge the heap */
  3184.  
  3185.     if (dItem==kAliasCancel)         /* go away without a trace */
  3186.             {        
  3187.             SetPort(savePort);
  3188.             LDispose(theList);
  3189.             DisposDialog( dtemp);
  3190.             ReleaseResource ((Handle)theResource);
  3191.             return;
  3192.             }
  3193.  
  3194.  
  3195.     if (dItem == kAliasOK)            /* save the changes for next time */
  3196.         {
  3197.         ChangedResource((Handle)theResource);
  3198.         UpdateResFile(HomeResFile((Handle) theResource));
  3199.         }
  3200.  
  3201.  
  3202.     SetPort(savePort);
  3203.     LDispose(theList);
  3204.     DisposDialog( dtemp);
  3205.     ReleaseResource((Handle)theResource);    
  3206. }
  3207.  
  3208.  
  3209.  
  3210.  
  3211.  
  3212. /* given an Alias Name, get all of the data about the host and port.
  3213.     This is called by SetUpPort, and is called whenever the user tries
  3214.     to open any connection.  Just check to see if the name is an alias. */
  3215.  
  3216. int GetDataFromAlias(char *theAlias, AliasRecord *theRecord)
  3217. {
  3218.     AliasRez **hAlias, *pAlias;
  3219.     short i;
  3220.     short found;
  3221.     
  3222.  
  3223.     hAlias = (AliasRez **)GetResource('alia',1000);
  3224.     if (hAlias == 0L) 
  3225.         return -1;
  3226.     
  3227.     HLock((Handle)hAlias);
  3228.     pAlias = *hAlias;
  3229.     
  3230.     found = 0;
  3231.     for (i=0;i < pAlias->number; i++)        /* found it!!  */
  3232.         if (strcmp(theAlias,pAlias->aliases[i].alias) ==0 )
  3233.             {
  3234.             strcpy(theRecord->name,pAlias->aliases[i].name);
  3235.             strcpy(theRecord->alias,pAlias->aliases[i].alias);
  3236.             theRecord->port = pAlias->aliases[i].port;
  3237.             found =1;
  3238.             }
  3239.  
  3240.     HUnlock((Handle)hAlias);
  3241.     ReleaseResource((Handle)hAlias);
  3242.     return found;
  3243. }
  3244.